【问题标题】:npm start command giving error in react appnpm start 命令在反应应用程序中给出错误
【发布时间】:2020-09-30 09:11:22
【问题描述】:

我使用了 npx create-react-app basic 并创建了 react 应用程序。然后我进入基本文件夹并尝试npm start,但它给了我以下错误:

npm start

basic@0.1.0 start C:\Users\91982\Desktop\html&css\React\basic
react-scripts start

'css\React\basic\node_modules\.bin\' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:985
  throw err;
  ^

Error: Cannot find module 'C:\Users\91982\Desktop\react-scripts\bin\react-scripts.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:982:15)
    at Function.Module._load (internal/modules/cjs/loader.js:864:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! basic@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the basic@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!     C:\Users\91982\AppData\Roaming\npm-cache\_logs\2020-06-10T19_54_37_385Z-debug.log

我什至尝试使用 npm 创建应用程序,但它给了我同样的错误。 start 脚本存在于 json 文件中。 npm 已更新到最新版本。

【问题讨论】:

  • 先删除node modules文件夹再重新安装。

标签: javascript reactjs npm web-development-server npm-start


【解决方案1】:

看来您没有安装依赖项。运行 npm inpm install 以安装依赖项。它没有找到 react-scripts 模块,因为它没有安装。

【讨论】:

  • 尽管它说它安装了 react-scripts 模块,但我还是再次安装了它,但我得到了同样的错误。您能否指定我需要安装哪些依赖项
【解决方案2】:

我认为这是您的 Windows PATH 环境变量的问题。它试图在本地项目node_modules目录中执行一些东西,但是windows找不到它,因为它不在路径中。

您可以尝试使用npx 命令代替npm

npx start

Npx 检查 PATH 和本地项目二进制文件的可执行文件。

【讨论】:

  • 如果你有 npm 5.2.0 及以上版本,npx 应该已经安装好了。您也可以使用npm install -g npx 手动安装它。另一种选择是将您的项目 node_modules bin 添加到您的 PATH 中。我的看起来像这样:C:\DSmith\vscode\projects\my-app\node_modules\.bin
  • 即使在将 \.bin 添加到路径后也会出现同样的错误。我也尝试将 react-scripts 添加到路径,但它没有用。 npm 和 node 是最新版本。
【解决方案3】:

您可以尝试以下方法:

  • cd 到你的项目目录(确保有 package.json 文件)
  • 删除node_modules目录
  • npm install && npm start

【讨论】:

    【解决方案4】:
    1. npm install create-react-app -g
    2. cd 你的项目文件夹
    3. 删除 node_modules 文件夹
    4. npm install && npm start

    【讨论】:

      【解决方案5】:

      我解决了这个问题。我必须将 C:/Windows/Systen32 添加到我的系统变量路径中。之后它开始工作。

      【讨论】:

        【解决方案6】:

        试试这个

        转到 > 控制面板\系统和安全\系统\高级系统设置\环境变量并设置系统变量路径 C:\Windows\System32\ 变量并重新启动系统。

        重新启动后它将工作 100%..

        谢谢

        【讨论】:

          猜你喜欢
          • 2020-01-26
          • 2022-06-11
          • 1970-01-01
          • 2018-12-10
          • 1970-01-01
          • 1970-01-01
          • 2021-11-24
          • 2020-08-31
          • 2018-12-28
          相关资源
          最近更新 更多