create-react-app 启动错误 - 错误:没有为“\node_modules\colorette”找到有效的导出 main

Mat*_*tan 27 reactjs create-react-app

安装时create-react-app,当我启动开发服务器(npm start)时出现此错误:

./src/index.css (./node_modules/css-loader/dist/cjs.js??ref--6-oneOf-3-1!./node_modules/postcss-loader/src??postcss!./src/index.css)
Error: No valid exports main found for 'myproject\node_modules\colorette'
Run Code Online (Sandbox Code Playgroud)

我已经重新安装了create-react-app全局create-react-app -g并尝试使用 运行它npx,但我仍然收到此错误。还有什么我可以做的吗?

Mat*_*tan 20

通过将 node.js 升级到 v14.5 解决了这个问题,我的笔记本电脑中有 v13.5 和 v13.6。并在全球范围内删除 create-react-app:

npm uninstall -g create-react-app
Run Code Online (Sandbox Code Playgroud)

并使用:

npx create-react-app myapp
Run Code Online (Sandbox Code Playgroud)

  • 降级到 12.18.2 也有帮助:在 package.json 中, "engines": { "node": "12.18.2" } (3认同)

小智 9

Node 版本 13 对 ReactJs 有问题,请检查您的版本。您可以更新或降级(LTS 版本)您的节点版本以正常运行 ReactJs


小智 6

您需要使用以下命令将节点版本升级到 14.5 或最新版本:

sudo n latest // on mac or linux for latest version
Run Code Online (Sandbox Code Playgroud)

对于 Windows,只需使用最新版本重新安装节点


小智 5

升级到 14.5 版将解决此问题。