我克隆了一个react应用程序到我的系统上,并运行以下命令

npm install -g create-react-app
npm install --save react react-dom

之后我就跑了

npm start 

但是它抛出了上面提到的错误,它在我的其他系统上工作得很好,我把它推到了github上。但克隆后,无论是windows还是mac,它都不能在任何其他系统上工作。


当前回答

在包中。json,我改变了

"start": "react-scripts start"

to

"start": "NODE_ENV=production node_modules/react-scripts/bin/react-scripts.js start"

我希望这能解决一些人的问题。虽然上面的其他解决方案似乎不适合我。

其他回答

如果您尝试了所有方法,但没有解决问题,请尝试重命名目录名称。如果文件夹名称包含大写字母,React将无法启动。

只需运行这些命令

npm install
npm start

or

yarn start

希望这对你有用 谢谢你!

这个变通办法对我很管用

// in your package.json replace 
"start": "react-scripts start"

// with:
"start": "node_modules/react-scripts/bin/react-scripts.js start"

我在yarn 1.15.1-1的最新版本中遇到了问题

我已经通过降级到低版本sudo apt-get install yarn=1.12.3-1来修复它

在macOS上用@/符号重命名目录以匹配我的NPM包命名空间的名称后,我遇到了这个错误。

当NPM命令在我的本地node_modules中寻找已安装的包时,由于macOS重写目录路径的方式,它无法找到它。在没有@/的情况下重命名目录后,我重新启动并运行。