【问题标题】:npm start suddenly stops working on react appnpm start 突然停止在 react 应用程序上工作
【发布时间】:2020-07-29 14:42:17
【问题描述】:

我已经学习 react 大约两个星期了,突然 npm start 无法运行。这就是我得到的:

sh: react-scripts: command not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! recipe-app@0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the recipe-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Michelle/.npm/_logs/2020-07-29T14_35_20_988Z-debug.log

经过大量的谷歌搜索后,我尝试了 npm install -g npm@latest 但权限被拒绝。

多次删除并重新安装节点,尝试使用 Homebrew 等,但没有任何效果。

编辑:找到解决方案! npm 找不到 react-scripts,所以我不得不将package.json 中的脚本更改为 "start": "node_modules/react-scripts/bin/react-scripts.js start".

【问题讨论】:

  • 运行命令时你确定你和你的 package.json 文件在同一个目录吗? - npm 在此查找命令
  • 运行npm时得到什么输出
  • @MikeW 在上面的帖子中添加了它
  • 我看到您是 StackOverflow 社区的新手。我建议您了解可以在帮助中心找到的内容。特别是本节:stackoverflow.com/help/someone-answers 特别是为了避免在您自己的问题中编写解决方案。
  • 别忘了将答案标记为最合适的答案 :)(即使是你的)

标签: reactjs npm


【解决方案1】:

你需要安装 react-scripts

npm install react-scripts

【讨论】:

    【解决方案2】:

    您刚刚发送的日志的第一行表明您的计算机不知道命令react-scripts。

    表示你需要安装它。

    当您将-g 选项与npm install 一起使用时,这意味着您要全局安装该软件包,并设置您计算机上的每个用户都可以访问该软件包。这就是您有权限错误的原因。您可以通过在命令之前添加sudo 或使用提升的用户运行它来解决此问题。

    全局安装包不是强制性的。

    我想您的package.json 文件包含一个名为start 的脚本,该脚本以react-scripts 开头。

    如果您使用npm install react-scripts 安装react-scripts 软件包,您会在node_modules/.bin/react-scripts 下找到二进制文件。

    然后您可以在您的start 脚本配置中将react-scripts 替换为./node_modules/.bin/react-scripts。

    package.json 文件示例:

    {
      "name": "myapp",
      "version": "1.0.0",
      ...
      "scripts": {
        ...
        "start": "./node_modules/.bin/react-scripts [...]",
        ...
      },
      ...
    }
    

    【讨论】:

    • 我试过安装 react 脚本,但还是不行。
    【解决方案3】:

    运行“npm install react-scripts”,即使我以前也为我工作过

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      • 1970-01-01
      • 2019-10-06
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多