繁体   English   中英

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

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

我有一个项目,我已经 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! 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.
  • 节点 6.7.0
  • npm 3.10.3
  • mac 塞拉 10.12

包.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"
  }
}

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

Create React App 的作者签入。

你绝对不应该全局安装react-scripts
也不需要./node_modules/react-scripts/bin/package.json正如这个答案所暗示的那样。

如果你看到这个:

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

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

我建议做这三个步骤:

  1. npm install -g npm@latest更新 npm,因为它有时有问题。
  2. rm -rf node_modules删除现有模块。
  3. npm install重新安装项目依赖项。

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

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

npm install -g react-scripts

或在您的 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"
  },

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

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

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

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

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

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

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

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

正如丹所说的那样,

如果你看到这个:

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

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

但是我得到了一些稍微不同的东西,因为运行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.

因此,我建议不要运行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.

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

我可能会很晚才回答这个问题,但这对我有用,它可能会帮助某人回到开发轨道!

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

干杯!!

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

npm i -S react-scripts

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

rm -r node_modules
npm i

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

npm install -g react-scripts

我遇到了以下问题。

在此处输入图片说明

请找到解决办法:

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

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

在此处输入图片说明

  1. 运行您的应用程序。

我在运行时遇到了同样的错误

启动

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.

我在几个选项卡上头晕目眩,并应用了其他开发人员的解决方案,但一无所获。

直到,即使使用 Ubuntu,我关闭了我的 vscode 并重新启动了我的电脑,我的所有问题都得到了解决。 (kkkk zueira) 就这一个。

在windows中添加环境变量

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

这5个是路径中必须的。

并使用最新版本的 node.js

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

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

希望它有帮助

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

很简单,但是第一次需要花几个步骤来设置!!!

  1. 您在节点上拥有最新版本。

  2. 转到环境变量并设置路径"%SystemRoot%\\system32"

在此处输入图片说明

  1. 以管理员模式运行cmd。

  2. 写命令 npm start。

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

当 node_modules 与 package.json 不同步时会发生这种情况。

在根目录和任何可能包含 node_modules 文件夹的子服务 /sub-folder 中运行以下命令。

rd node_modules /S /Q
npm install

我想到了,但以上都没有奏效。

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)

发生这种情况是因为您可能已经全局安装了react-scripts

为了使这项工作...

  1. 转到您的C:\\Users\\<USER>\\AppData\\Roaming
  2. 删除 npm 和 npm-cache 目录...(不用担心你以后可以全局安装 npm)
  3. 返回您的应用程序目录并删除node_modules文件夹
  4. 现在输入npm install安装依赖项(如果已经创建,请删除 package-lock.json)
  5. 现在运行npm install --save react react-dom react-scripts
  6. 使用npm start

这应该让你回到正轨......快乐编码

我的问题源于权限问题。 我按照这个https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally解决了我的问题

在终端中输入unset HOST

我在本地创建了反应项目。 发生这个问题的原因(对我来说)是我在npm之前没有使用sudo并且它需要root访问权限(

> sudo npm start

PS1 :对于windows用户, powershellcommand line应该以管理员身份运行

PS2 :如果用户想解决root访问问题,你可以看这个帖子

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

只需删除“node_module”文件,如果它在文件夹中看起来有点灰色,则意味着它不在那里,只需关闭 vs 代码并重新打开即可

使用“npm install”安装 npm。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM