简体   繁体   English

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

[英]npm start error with create-react-app

I have a project who I didn't touch for 2 weeks.我有一个项目,我已经 2 周没碰过了。 I take it back and now when I try to run npm start I got this error.我收回它,现在当我尝试运行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! UpScore@0.6.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the UpScore@0.6.0 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节点 6.7.0
  • npm 3.10.3 npm 3.10.3
  • mac sierra 10.12 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谢谢

Author of Create React App checking in. Create React App 的作者签入。

You absolutely should not be installing react-scripts globally.你绝对不应该全局安装react-scripts
You also don't need ./node_modules/react-scripts/bin/ in package.json as this answer implies.也不需要./node_modules/react-scripts/bin/package.json正如这个答案所暗示的那样。

If you see this:如果你看到这个:

npm ERR! UpScore@0.6.0 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@latest to update npm because it is sometimes buggy. npm install -g npm@latest更新 npm,因为它有时有问题。
  2. rm -rf node_modules to remove the existing modules. rm -rf node_modules删除现有模块。
  3. npm install to re-install the project dependencies. npm install重新安装项目依赖项。

This should fix the problem.这应该可以解决问题。
If it doesn't, please file an issue with a link to your project and versions of Node and npm.如果没有,请提交一个问题,并提供指向您的项目以及 Node 和 npm 版本的链接。

It seems like you don't have react-scripts in your global environment.您的全球环境中似乎没有react-scripts Two possibility are available here :这里有两种可能性:

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"
  },

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

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

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.花了很长时间,起初看起来与 OP 错误相似,但略有不同。 This starts with ERRNO 4058 and continues with code 'ENOENT' syscall: 'spawn cmd', path: ''cmd' ...这从 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.最终从 github create-react-app 论坛中发现,对此的快速解决方法是在“路径”变量中注册 cmd。 To do this go to System Properties>Environment variables.为此,请转到系统属性>环境变量。 Click on path variable edit and and add new entry of C:\\Windows\\System32.单击路径变量编辑并添加新条目 C:\\Windows\\System32。 Restart CMD prompt and I was good to go.重新启动 CMD 提示,我很高兴。

As Dan said correctly,正如丹所说的那样,

If you see this:如果你看到这个:

npm ERR! UpScore@0.6.0 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@latest to 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.这应该会让你重新站起来。

I might be very late to answer this question but this is what has worked for me and it might help someone to get back on the development track!我可能会很晚才回答这个问题,但这对我有用,它可能会帮助某人回到开发轨道!

nvm install v12.0 // You may need to install nvm, if not already done
rm -rd node_modules/
npm cache clean --force
npm install

Cheers!!干杯!!

For me it was simply that I hadn't added react-scripts to the project so:对我来说,这只是因为我没有在项目中添加react-scripts所以:

npm i -S react-scripts

If this doesn't work, then rm node_modules as suggested by others如果这不起作用,则按照其他人的建议 rm node_modules

rm -r node_modules
npm i

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

npm install -g react-scripts

I have faced the following issue.我遇到了以下问题。

在此处输入图片说明

Please find the solution:请找到解决办法:

  1. Add "C:\\Windows\\System32" to the global PATH environment variable.“C:\\Windows\\System32”添加到全局 PATH 环境变量中。

  2. Check whether the environment variables has been created for nodejs,npm and composer .检查是否已经为nodejs、npm 和 composer创建了环境变量。 if not create one如果不创建一个

在此处输入图片说明

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

I had the same error when running我在运行时遇到了同样的错误

npm start启动

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! protest-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the protest-app@0.1.0 start script.

I broke my head on several tabs and applying Solutions from other devs and nothing.我在几个选项卡上头晕目眩,并应用了其他开发人员的解决方案,但一无所获。

Until, even using Ubuntu, I closed my vscode and restarted my pc and all my problems were solved.直到,即使使用 Ubuntu,我关闭了我的 vscode 并重新启动了我的电脑,我的所有问题都得到了解决。 (kkkk zueira) just this one. (kkkk zueira) 就这一个。

add environment variables in windows在windows中添加环境变量

  1. C:\\WINDOWS\\System32 C:\\WINDOWS\\System32
  2. C:\\Program Files\\nodejs C:\\Program Files\\nodejs
  3. C:\\Program Files\\nodejs\\node_modules\\npm\\bin C:\\Program Files\\nodejs\\node_modules\\npm\\bin
  4. C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0 C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0
  5. C:\\Users{your system name without curly braces}\\AppData\\Roaming\\npm C:\\Users{你的系统名称不带花括号}\\AppData\\Roaming\\npm

these 5 are must in path.这5个是路径中必须的。

and use the latest version of node.js并使用最新版本的 node.js

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希望它有帮助

添加带有“SKIP_PREFLIGHT_CHECK=true”的 .env 文件而不是 npm start

it is simple but the first time it takes time a few steps to set !!!很简单,但是第一次需要花几个步骤来设置!!!

  1. you have the latest version on node.您在节点上拥有最新版本。

  2. go to the environment variable and set the path "%SystemRoot%\\system32" .转到环境变量并设置路径"%SystemRoot%\\system32"

在此处输入图片说明

  1. run cmd as administrator mode.以管理员模式运行cmd。

  2. write command npm start.写命令 npm start。

可能与其他库冲突,删除 node_modules 并再次 npm install。

This occurs when the node_modules gets out of sync with package.json.当 node_modules 与 package.json 不同步时会发生这种情况。

Run the following at the root and any sub service /sub-folder that might have node_modules folder within it.在根目录和任何可能包含 node_modules 文件夹的子服务 /sub-folder 中运行以下命令。

rd node_modules /S /Q
npm install

It occurred to me but none of the above worked.我想到了,但以上都没有奏效。

events.js:72
        throw er; // Unhandled 'error' event
              ^

npm ERR! UpScore@0.6.0 start: `react-scripts start`
npm ERR! spawn ENOENT

Error: spawn ENOENT
    at errnoException (child_process.js:1000:11)
    at Process.ChildProcess._handle.onexit (child_process.js:791:34)

This happens because you might have installed react-scripts globally.发生这种情况是因为您可能已经全局安装了react-scripts

To make this work...为了使这项工作...

  1. Go to your C:\\Users\\<USER>\\AppData\\Roaming转到您的C:\\Users\\<USER>\\AppData\\Roaming
  2. Delete npm and npm-cache directories ... (don't worry you can install npm globally later)删除 npm 和 npm-cache 目录...(不用担心你以后可以全局安装 npm)
  3. Go back to your application directory and remove node_modules folder返回您的应用程序目录并删除node_modules文件夹
  4. Now enter npm install to install the dependencies (delete package-lock.json if its already created)现在输入npm install安装依赖项(如果已经创建,请删除 package-lock.json)
  5. Now run npm install --save react react-dom react-scripts现在运行npm install --save react react-dom react-scripts
  6. Get it started with npm start使用npm start

This should get you back on track... Happy Coding这应该让你回到正轨......快乐编码

My issue was stemming from permission issues.我的问题源于权限问题。 I solved mine by following this https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally我按照这个https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally解决了我的问题

在终端中输入unset HOST

I have created react project locally.我在本地创建了反应项目。 This reason of occurring this problem (for me) was that I didn't use sudo before npm and it needs root access (发生这个问题的原因(对我来说)是我在npm之前没有使用sudo并且它需要root访问权限(

> sudo npm start

PS1 : For windows users, the powershell or command line should be run as administrator ) PS1 :对于windows用户, powershellcommand line应该以管理员身份运行

PS2 : If use want to solve the root access issue, you can see this post . PS2 :如果用户想解决root访问问题,你可以看这个帖子

我在项目中运行npm install然后npm start它起作用了

just delete the "node_module" file and if its seems somehow grey in folder that means it's not there just close the vs code and re open then只需删除“node_module”文件,如果它在文件夹中看起来有点灰色,则意味着它不在那里,只需关闭 vs 代码并重新打开即可

install npm with "npm install".使用“npm install”安装 npm。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 可以用 Nodejs 开头的 Create-React-App npm 吗? - Can you use Create-React-App npm start with nodejs? npm 使用 create-react-app 时启动不运行 - npm start not running when using create-react-app npx create-react-app 在运行 npm 启动时出错 - npx create-react-app gives error when running npm start 使用 npx create-react-app 创建应用后<myproject> ,并使用“npm start”启动应用程序我得到了下面提到的这个错误</myproject> - After creating app using npx create-react-app <myproject> , and start app by using "npm start" i got this error mentioned below 然后尝试 create-react-app 时出错(npm ERR!cb() never call!然后尝试 create-react-app) - Error then trying create-react-app( npm ERR! cb() never called! then trying create-react-app) 尝试在 create-react-app 中导入 npm 时出错 - Error while trying to import npm got in create-react-app 使用 npm create-react-app 不起作用? - using npm create-react-app is not working? 使用 create-react-app 创建新的 react 项目后,npm start 失败 - npm start fails after creating a new react project using create-react-app 我可以在没有 npm 启动和 npx create-react-app 的情况下使用 React 运行 index.html 吗? - Can I run index.html with React without npm start and npx create-react-app? 使用 create-react-app (npm start) 运行项目时如何在 Chrome 上启用地理定位? - How to enable geolocation on Chrome when running a project with create-react-app (npm start)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM