Javascript 使用 create-react-app 启动 npm 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39959900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 23:05:00  来源:igfitidea点击:

npm start error with create-react-app

javascriptreactjscreate-react-app

提问by EQuimper

I have a project who I didn't touch for 2 weeks. I take it back and now when I try to run npm startI got this error.

我有一个项目,我已经 2 周没碰过了。我收回它,现在当我尝试运行时npm start出现此错误。

> react-scripts start

sh: react-scripts: command not found

npm ERR! Darwin 16.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.7.0
npm ERR! npm  v3.10.3
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! [email protected] start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] start script 'react-scripts start'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the UpScore package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     react-scripts start
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs UpScore
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls UpScore
npm ERR! There is likely additional logging output above.
  • node 6.7.0
  • npm 3.10.3
  • mac sierra 10.12
  • 节点 6.7.0
  • npm 3.10.3
  • mac 塞拉 10.12

package.json

包.json

{
  "name": "UpScore",
  "version": "0.6.0",
  "private": true,
  "devDependencies": {
    "react-addons-test-utils": "^15.3.1",
    "react-scripts": "0.4.1",
    "react-test-renderer": "^15.3.1",
    "redux-logger": "^2.6.1"
  },
  "dependencies": {
    "@yoshokatana/medium-button": "^1.1.0",
    "axios": "^0.14.0",
    "bcrypt": "^0.8.7",
    "bcrypt-nodejs": "0.0.3",
    "bcryptjs": "^2.3.0",
    "body-parser": "^1.15.2",
    "connect-flash": "^0.1.1",
    "cookie-parser": "^1.4.3",
    "draft-js": "^0.8.1",
    "draft-js-editor": "^1.7.2",
    "draft-js-export-html": "^0.4.0",
    "ejs": "^2.5.2",
    "email-verification": "^0.4.5",
    "express": "^4.14.0",
    "express-session": "^1.14.1",
    "flexboxgrid": "^6.3.1",
    "highlight.js": "^9.6.0",
    "immutable": "^3.8.1",
    "katex": "^0.6.0",
    "lodash": "^4.15.0",
    "markdown-it-mathjax": "^1.0.3",
    "material-ui": "^0.15.4",
    "medium-editor": "^5.22.0",
    "minutes-seconds-milliseconds": "^1.0.3",
    "moment": "^2.15.0",
    "moment-duration-format": "^1.3.0",
    "mongod": "^1.3.0",
    "mongodb": "^2.2.9",
    "mongoose": "^4.6.0",
    "monk": "^3.1.2",
    "morgan": "^1.7.0",
    "normalize.css": "^3.0.3",
    "passport": "^0.3.2",
    "passport-local": "^1.0.0",
    "react": "^15.3.1",
    "react-dom": "^15.3.1",
    "react-markdown": "^2.4.2",
    "react-medium-editor": "^1.8.1",
    "react-redux": "^4.4.5",
    "react-redux-form": "^0.14.5",
    "react-rich-markdown": "^1.0.1",
    "react-router": "^2.7.0",
    "react-router-redux": "^4.0.5",
    "react-tap-event-plugin": "^1.0.0",
    "react-tinymce": "^0.5.1",
    "redux": "^3.6.0",
    "redux-form": "^6.0.5",
    "redux-form-material-ui": "^4.0.1",
    "redux-promise-middleware": "^4.0.0",
    "redux-thunk": "^2.1.0",
    "reselect": "^2.5.3",
    "screenfull": "^3.0.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "start:prod": "pushstate-server build",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject",
    "server": "cd client/api && pm2 start server.js --watch",
    "proxy": "http://128.199.139.144:3000"
  },
  "eslintConfig": {
    "extends": "./node_modules/react-scripts/config/eslint.js"
  }
}

I try to clone my repos too and get the same error. If someone can give me some way to find what happen. Thank you

我也尝试克隆我的存储库并得到相同的错误。如果有人能给我一些方法来找出发生了什么。谢谢

回答by Dan Abramov

Author of Create React App checking in.

Create React App 的作者签入。

You absolutely should not be installing react-scriptsglobally.
You also don'tneed ./node_modules/react-scripts/bin/in package.jsonas this answerimplies.

您绝对不应该react-scripts全局安装。
如此答案所暗示的那样,您也不需要./node_modules/react-scripts/bin/in 。package.json

If you see this:

如果你看到这个:

npm ERR! [email protected] start: `react-scripts start`
npm ERR! spawn ENOENT

It just means something went wrong when dependencies were installed the first time.

这只是意味着第一次安装依赖项时出现问题。

I suggest doing these three steps:

我建议做这三个步骤:

  1. npm install -g npm@latestto update npm because it is sometimes buggy.
  2. rm -rf node_modulesto remove the existing modules.
  3. npm installto re-install the project dependencies.
  1. npm install -g npm@latest更新 npm 因为它有时有问题。
  2. rm -rf node_modules删除现有模块。
  3. npm install重新安装项目依赖项。

This should fix the problem.
If it doesn't, please file an issuewith a link to your project and versions of Node and npm.

这应该可以解决问题。
如果没有,请提交一个问题,并提供指向您的项目以及 Node 和 npm 版本的链接。

回答by Steeve Pitis

It seems like you don't have react-scriptsin your global environment. Two possibility are available here :

react-scripts您的全球环境中似乎没有。这里有两种可能性:

npm install -g react-scripts

npm install -g react-scripts

or in your package.json change your script part like this :

或在您的 package.json 中更改您的脚本部分,如下所示:

  "scripts": {
    "start": "./node_modules/react-scripts/bin/react-scripts.js start",
    "start:prod": "pushstate-server build",
    "build": "./node_modules/react-scripts/bin/react-scripts.js build",
    "test": "./node_modules/react-scripts/bin/react-scripts.js test --env=jsdom",
    "eject": "./node_modules/react-scripts/bin/react-scripts.js eject",
    "server": "cd client/api && pm2 start server.js --watch",
    "proxy": "http://128.199.139.144:3000"
  },

回答by Chtiwi Malek

Yes you should not install react-scripts globally, it will not work.

是的,你不应该全局安装 react-scripts,它不会工作。

I think i didn't use the --save when i first created the project (on another machine), so for me this fixed the problem :

我想我第一次创建项目(在另一台机器上)时没有使用 --save ,所以对我来说这解决了问题:

npm install --save react react-dom react-scripts

回答by Tony_GR

This is to help others completely new to react and who area having problems just starting a first app even though they did a fresh install and try using npm install and the other fixes I saw around the forums.

这是为了帮助其他全新的人做出反应,以及谁在启动第一个应用程序时遇到问题,即使他们进行了全新安装并尝试使用 npm install 和我在论坛中看到的其他修复程序。

Running it on Windows 10 with all the latest npm create-react-app installed and got failure after failure on a simple npm start in a simple my-app demo folder.

在安装了所有最新 npm create-react-app 的 Windows 10 上运行它,并在一个简单的 my-app 演示文件夹中的简单 npm start 失败后失败。

Spent a long time with what looks similar to the OP error at first but is slightly different. This starts with ERRNO 4058 and continues with code 'ENOENT' syscall: 'spawn cmd', path: ''cmd' ...

花了很长时间,起初看起来与 OP 错误相似,但略有不同。这从 ERRNO 4058 开始,并以代码 'ENOENT' syscall: 'spawn cmd', path: ''cmd' ...

Eventually worked out from github create-react-app forum that a quick fix for this is registering cmd in the "path" variable. To do this go to System Properties>Environment variables. Click on path variable edit and and add new entry of C:\Windows\System32. Restart CMD prompt and I was good to go.

最终从 github create-react-app 论坛中发现,对此的快速解决方法是在“路径”变量中注册 cmd。为此,请转到系统属性>环境变量。单击路径变量编辑并添加新条目 C:\Windows\System32。重新启动 CMD 提示,我很高兴。

回答by antzshrek

As Dan said correctly,

正如丹所说的那样,

If you see this:

如果你看到这个:

npm ERR! [email protected] start: `react-scripts start`
npm ERR! spawn ENOENT

It just means something went wrong when dependencies were installed the first time.

这只是意味着第一次安装依赖项时出现问题。

But I got something slightly different because running npm install -g npm@latestto update npm might sometimes leave you with this error:

但是我得到了一些稍微不同的东西,因为运行npm install -g npm@latest更新 npm 有时可能会给你带来这个错误:

npm ERR! code ETARGET
npm ERR! notarget No matching version found for npm@lates
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

so, instead of running npm install -g npm@latest, I suggest running the below steps:

所以,npm install -g npm@latest我建议不要运行,而是运行以下步骤:

 npm i -g npm //which will also update npm
 rm -rf node_modules/ && npm cache clean // to remove the existing modules and clean the cache.
 npm install //to re-install the project dependencies.

This should get you back on your feet.

这应该会让你重新站起来。

回答by Jamie Hutber

For me it was simply that I hadn't added react-scriptsto the project so:

对我来说,这只是我没有添加react-scripts到项目中,所以:

npm i -S react-scripts

If this doesn't work, then rm node_modulesas suggested by others

如果这不起作用,则node_modules按照其他人的建议rm

rm -r node_modules
npm i

回答by Flavins

incase you happened to be so unlucky like me that spent three(3) days in a row trying to solve this problem every solution proposed here failed me ... create a .env file in your project root and add this code SKIP_PREFLIGHT_CHECK=true. Good luck

如果你碰巧像我一样不幸,连续三(3)天试图解决这个问题,这里提出的每个解决方案都让我失望......在你的项目根目录中创建一个 .env 文件并添加此代码SKIP_PREFLIGHT_CHECK=true。祝你好运

回答by Usama Majid

I fix this using this following command:

我使用以下命令修复此问题:

npm install -g react-scripts

回答by Gopinath gops

I have faced the following issue.

我遇到了以下问题。

enter image description here

在此处输入图片说明

Please find the solution:

请找到解决方法:

  1. Add "C:\Windows\System32"to the global PATH environment variable.

  2. Check whether the environment variables has been created for nodejs,npm and composer. if not create one

  1. “C:\Windows\System32”添加到全局 PATH 环境变量中。

  2. 检查是否已经为nodejs、npm 和 composer创建了环境变量。如果不创建一个

enter image description here

在此处输入图片说明

  1. Run your app.
  1. 运行您的应用程序。

回答by Krishna Kumar Jangid

I solve this issue by running following command

我通过运行以下命令解决了这个问题

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

hope it helps

希望能帮助到你