create-react-app-react-scripts:找不到命令

时间:2018-11-24 16:40:38

标签: reactjs npm

我刚开始对Codepen做出反应,我非常喜欢!我决定将其安装在MacBook Air上。我使用npm安装了create-react-app,一切看起来都不错。然后,我开始了一个项目,一切顺利。当我运行npm start时,出现错误:
sh: react-scripts: command not found npm ERR! file sh npm ERR! code ELIFECYCLE npm ERR! errno ENOENT npm ERR! syscall spawn npm ERR! react-app@0.1.0 start: 'react-scripts start' npm ERR! spawn ENOENT npm ERR! npm ERR! Failed at the react-app@0.1.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

我得出的结论是npm找不到反应脚本。我几乎完成了我想出的所有事情:更新了npm;我已经重新安装了模块;我已经开始了一个新项目,但是仍然遇到相同的错误。我已经检查过,react-scripts在我的node_modules文件中。我唯一没有做的就是在全球范围内安装react-scripts,但是create-react-app的创建者说这是一个非常糟糕的主意。我该怎么办?

4 个答案:

答案 0 :(得分:1)

请尝试先运行npm install,然后再运行npm start,如果这样做不起作用,请查看关于同一问题的这篇文章-sh: react-scripts: command not found after running npm start

答案 1 :(得分:1)

刚刚解决了这个问题:

package.json中,我将"start": react-scripts start"更改为"start": "NODE_ENV=production node_modules/react-scripts/bin/react-scripts.js start"。这样就解决了问题。

答案 2 :(得分:0)

添加整个路径也对我有用: "start": "node_modules/react-scripts/bin/react-scripts.js start"

不仅是: "start": "react-scripts start"

我希望我知道为什么此行为在我的PC中发生了变化。 是否巧合,我今天更新了我的xcode。

答案 3 :(得分:0)

删除package-lock.json: sudo rm package-lock.json

删除node_modules: sudo rm -rf node_modules

(可选)升级npm: sudo npm install -g npm

然后再次安装项目 npm i

运行项目: npm start

在您描述的情况下为我工作