【问题标题】:create-react-app - react-scripts: command not foundcreate-react-app - react-scripts:找不到命令
【发布时间】:2019-04-26 20:47:48
【问题描述】:

我刚开始在 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 找不到 react-scripts。我已经完成了我想出的几乎所有事情:我更新了 npm;我已经重新安装了模块;我已经开始了一个新项目,但我仍然遇到同样的错误。我已经检查过了,react-scripts 在我的 node_modules 文件中。我唯一没有做的是全局安装 react-scripts,但是 create-react-app 的创建者说这是一个非常糟糕的主意。我该怎么办?

【问题讨论】:

标签: reactjs npm


【解决方案1】:

在运行 npm start 之前尝试运行 npm install,如果这不起作用,请查看有关同一问题的这篇文章 - sh: react-scripts: command not found after running npm start

【讨论】:

  • 您是否尝试过该帖子中的所有步骤?比如重新启动系统并将 NODE_ENV 设置为开发?
【解决方案2】:

刚刚解决了问题:

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

【讨论】:

    【解决方案3】:

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

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

    我希望我知道为什么我的电脑会发生这种行为。 巧合与否,我今天更新了我的 xcode。

    【讨论】:

      【解决方案4】:

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

      删除节点模块: sudo rm -rf node_modules

      可选择升级 npm: sudo npm install -g npm

      然后再次安装项目 npm i

      运行项目: npm start

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

      【讨论】:

        猜你喜欢
        • 2021-04-02
        • 2018-01-09
        • 2019-11-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-02
        • 2019-12-30
        • 2016-12-09
        相关资源
        最近更新 更多