我试图学习react,所以我有这个全堆栈react投票应用程序的示例代码,我试图让它工作,但在运行npm安装后,紧接着npm启动,当我运行npm启动时,我收到以下错误,任何人都可以帮助我解决这个问题:

npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "server"
npm ERR! node v7.5.0
npm ERR! npm  v4.3.0
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! voting_app@1.1.0 server: `live-server --public --    
host=localhost --port=3000 --middleware=./disable-browser-cache.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the voting_app@1.1.0 server script 'live-server --
public --host=localhost --port=3000 --middleware=./disable-browser- 
cache.js'.
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 voting_app  
package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     live-server --public --host=localhost --port=3000 --  
middleware=./disable-browser-cache.js
npm ERR! You can get information on how to open an issue for this  
project with:
npm ERR!     npm bugs voting_app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls voting_app
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/ItsMeMrLi/.npm/_logs/2017-02-17T22_48_03_581Z-
debug.log

npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v7.5.0
npm ERR! npm  v4.3.0
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! voting_app@1.1.0 start: `npm run server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the voting_app@1.1.0 start script 'npm run server'.
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 voting_app    
package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run server

npm ERR! You can get information on how to open an issue for this   
project with:
npm ERR!     npm bugs voting_app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls voting_app
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/ItsMeMrLi/.npm/_logs/2017-02-17T22_48_03_655Z-
debug.log

这是我的package.json:

{
  "name": "voting_app",
  "version": "1.1.0",
  "author": "Fullstack.io",
  "scripts": {
    "go": "open http://localhost:3000; npm run server",
    "e2e": "nightwatch",
    "test": "./node_modules/.bin/concurrently -k 'npm run server' 'npm  
run e2e'",
    "start": "npm run server",
    "server": "live-server public --host=localhost --port=3000 --  
middleware=./disable-browser-cache.js"
  },
  "private": true,
  "devDependencies": {
  "concurrently": "2.2.0",
  "live-server": "git://github.com/acco/live-server.git"
},
  "dependencies": {
  "semantic-ui": "git://github.com/Semantic-Org/Semantic-
  UI.git#27d58a01793b66318478fbc5b6676804d22d065d"
  }
}

最后是我的日志文件:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@4.3.0
3 info using node@v7.5.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle voting_app@1.1.0~prestart: voting_app@1.1.0
6 silly lifecycle voting_app@1.1.0~prestart: no script for prestart, continuing
7 info lifecycle voting_app@1.1.0~start: voting_app@1.1.0
8 verbose lifecycle voting_app@1.1.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle voting_app@1.1.0~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/ItsMeMrLi/Downloads/fullstack-react-code/voting_app/node_modules/.bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Users/ItsMeMrLi/.rvm/gems/ruby-2.3.1/bin:/Users/ItsMeMrLi/.rvm/gems/ruby-2.3.1@global/bin:/Users/ItsMeMrLi/.rvm/rubies/ruby-2.3.1/bin:/Users/ItsMeMrLi/.cargo/bin:/usr/local/Cellar/smlnj/110.74/libexec/bin:/usr/local/bin:/Users/ItsMeMrLi/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Downloads/geckodriver:/usr/local/bin:/Users/ItsMeMrLi/.rvm/bin
10 verbose lifecycle voting_app@1.1.0~start: CWD: /Users/ItsMeMrLi/Downloads/fullstack-react-code/voting_app
11 silly lifecycle voting_app@1.1.0~start: Args: [ '-c', 'npm run server' ]
12 silly lifecycle voting_app@1.1.0~start: Returned: code: 1  signal: null
13 info lifecycle voting_app@1.1.0~start: Failed to exec start script
14 verbose stack Error: voting_app@1.1.0 start: `npm run server`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:192:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:192:7)
14 verbose stack     at maybeClose (internal/child_process.js:890:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid voting_app@1.1.0
16 verbose cwd /Users/ItsMeMrLi/Downloads/fullstack-react-code/voting_app
17 error Darwin 16.4.0
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
19 error node v7.5.0
20 error npm  v4.3.0
21 error code ELIFECYCLE
22 error errno 1
23 error voting_app@1.1.0 start: `npm run server`
23 error Exit status 1
24 error Failed at the voting_app@1.1.0 start script 'npm run server'.
24 error Make sure you have the latest version of node.js and npm installed.
24 error If you do, this is most likely a problem with the voting_app package,
24 error not with npm itself.
24 error Tell the author that this fails on your system:
24 error     npm run server
24 error You can get information on how to open an issue for this project with:
24 error     npm bugs voting_app
24 error Or if that isn't available, you can get their info via:
24 error     npm owner ls voting_app
24 error There is likely additional logging output above.
25 verbose exit [ 1, true ]

当前回答

据我所知,ELIFECYCLE基本上意味着您正在尝试使用已经达到生命周期结束的包。更新包对我有用。

尝试完全更新最新的稳定版本的nodejs和npm:

sudo apt -y update && sudo apt -y upgrade

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

sudo apt -y update && sudo apt -y upgrade
sudo apt -y autoremove

然后,更改目录到您的应用程序目录:

cd myapp/ #Change this to match your app directory

删除node_modules文件夹

sudo rm -rf node_modules/

然后重新安装软件包:

npm i

看看你的应用是否构建成功:

npm run build

其他回答

我的情况需要全局删除webpack文件夹,然后删除项目node_modules文件夹,package-lock。运行NPM install, NPM start

我建议您将节点版本更新到应用程序推荐的最新节点版本,或者简单地更新节点版本。我在使用11.1版本的节点时遇到了同样的问题,但我的应用程序建议至少使用10.x版本。X或12.x.x 我在这个线程上尝试了所有建议的回复,但似乎都不起作用,直到我将节点版本更新到推荐的最新版本。版本12.16.3,然后我的应用程序运行。

在我的例子中,以下是有效的:

我使用节点版本管理器,因为一些项目运行在旧版本的node . js上

确保项目失败运行的是正确的Node版本。

NVM使用“正确的节点版本”

npm安装 NPM start应该这样做。

一个可能意想不到的原因:你使用Create React App时,有些警告没有修复,项目在CI上失败了(例如GitLab CI/CD):

Treating warnings as errors because process.env.CI = true.
[ ... some warnings here ...]
npm ERR! code ELIFECYCLE
npm ERR! errno 1

解决方案:修复你的警告!

替代方案:使用CI=false npm运行构建

参见CRA第3657期

(不好意思承认这只是发生在我身上;直到同事指出来我才发现。谢谢帕斯卡!)

这与我的NPM包无关。我的Vuepress项目使用了一个自定义主机名。省略了这一点,事情又开始运转了。