node.js 错误!代码生命周期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42308879/
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-09-02 18:00:56  来源:igfitidea点击:

npm ERR! code ELIFECYCLE

node.jsnpm-installnpm-start

提问by Y'Eli Buonya

I'm trying to learn react, so I have this sample code for the fullstack react voting app, and I am trying to get it work but after running npm install followed by npm start I receive the following error:

我正在尝试学习 react,所以我有这个 fullstack react 投票应用程序的示例代码,我试图让它工作,但是在运行 npm install 和 npm start 之后,我收到以下错误:

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! [email protected] server: `live-server --public --    
host=localhost --port=3000 --middleware=./disable-browser-cache.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] 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! [email protected] start: `npm run server`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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

Here is my package.json:

这是我的 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"
  }
}

And finally my log file:

最后是我的日志文件:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle [email protected]~prestart: [email protected]
6 silly lifecycle [email protected]~prestart: no script for prestart, continuing
7 info lifecycle [email protected]~start: [email protected]
8 verbose lifecycle [email protected]~start: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~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 [email protected]~start: CWD: /Users/ItsMeMrLi/Downloads/fullstack-react-code/voting_app
11 silly lifecycle [email protected]~start: Args: [ '-c', 'npm run server' ]
12 silly lifecycle [email protected]~start: Returned: code: 1  signal: null
13 info lifecycle [email protected]~start: Failed to exec start script
14 verbose stack Error: [email protected] 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 [email protected]
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 [email protected] start: `npm run server`
23 error Exit status 1
24 error Failed at the [email protected] 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 ]

Thanks all you awesome programmers.

感谢所有出色的程序员。

回答by Prakhar Mittal

Step 1: $ npm cache clean --force

第1步: $ npm cache clean --force

Step 2: Delete node_modulesby $ rm -rf node_modules package-lock.jsonfolder or delete it manuallyby going into the directory and right-click > delete / move to trash. Also, delete package-lock.jsonfile too.

步骤2:按文件夹删除node_modules$ rm -rf node_modules package-lock.json或通过进入目录并右键单击>删除/移至垃圾箱来手动删除它。另外,也删除package-lock.json文件。

Step 3: npm install

第 3 步: npm install

To start again, $ npm start

重新开始, $ npm start

This worked for me. Hopes it works for you too.

这对我有用。希望它也适用于你。

PS: Still if it is there, kindly check the error it is displaying in red and act accordingly. This error is specific to node.js environment. Happy Coding!!

PS:如果它仍然存在,请检查它以红色显示的错误并采取相应措施。此错误特定于 node.js 环境。快乐编码!!

回答by Babak Habibi

Cleaning Cacheand Node_moduleare not enough. Follow this steps:

清洁CacheNode_module不够。请按照以下步骤操作:

  • npm cache clean --force
  • delete node_modulesfolder
  • delete package-lock.jsonfile
  • npm install
  • npm cache clean --force
  • 删除node_modules文件夹
  • 删除package-lock.json文件
  • npm install

It works for me like this.

它像这样对我有用。

回答by tonycor nikolauos

first i ran:

首先我跑了:

npm run clean

(even though it came with errors)

(即使它带有错误)

Then i deleted the node_modulesfolder and ran

然后我删除了node_modules文件夹并运行

npm install

This seems to have solved the problem.

这似乎解决了问题。

回答by Uditha Prasad

I resolve this error running following code

我解决了运行以下代码的错误

npm cache clean

then delete node_modulesdirectory from my project structure manually or with following command

然后node_modules手动或使用以下命令从我的项目结构中删除目录

rm -rf node_modules

After That install dependencies again using

之后再次使用安装依赖项

npm install

回答by Smokie

Change access in node_modules directory

更改 node_modules 目录中的访问权限

chmod -R a+rwx ./node_modules 

回答by Keith Axline

I was getting similar error messages on a 16.04 Ubuntu instance with DigitalOcean while running npm run buildon an app made with create-react-app(link). I upgraded the instance from 512MB RAM to 1GB ($5/mo to $10/mo) and then the script was able to run.

npm run build在使用create-react-app链接)制作的应用程序上运行时,我在带有 DigitalOcean 的 16.04 Ubuntu 实例上收到了类似的错误消息。我将实例从 512MB RAM 升级到 1GB(5 美元/月到 10 美元/月),然后脚本就可以运行了。

I post this here to point out that you may get this error due to resource limitations, which I didn't really see explained elsewhere on issue pages and SO answers. And nothing I saw in the error logs pointed me in this direction.

我在这里发帖是为了指出由于资源限制,您可能会收到此错误,我并没有在问题页面和 SO 答案的其他地方真正看到解释。我在错误日志中看到的任何内容都没有指向这个方向。

回答by Eddie Teixeira

Delete node_modules and package-lock.json, and then run npm install. It worked perfectly here(run command below inside project root):

删除 node_modules 和 package-lock.json,然后运行 ​​npm install。它在这里工作得很好(在项目根目录下面运行命令):

rm -rf node_modules && rm ./package-lock.json && npm install

回答by NuOne

Faced this exact problem,

面对这个确切的问题,

for me it worked by deletingpackage-lock.jsonand re run npm install

对我来说它有效deletingpackage-lock.json并重新运行npm install

if it doesn't resolve try

如果它没有解决尝试

  1. delete package-lock.json
  2. npm cache clean --force
  3. npm install
  4. npm start
  1. 删除 package-lock.json
  2. npm 缓存清理 --force
  3. 安装
  4. 启动

回答by adSad

React Application: For me the issue was that after running npm installhad some errors.

React Application:对我来说,问题是运行后npm install出现了一些错误。

I've went with the recommendation npm audit fix. This operation broke my package.jsonand package-lock.json(changed version of packages and and structure of .json).

我已经按照推荐去了npm audit fix。此操作破坏了我的package.jsonpackage-lock.json(更改了包的版本和 .json 的结构)。

THE FIX WAS:

修复是:

  • Delete node_modules
  • Run npm install
  • npm start
  • 删除 node_modules
  • npm install
  • npm start

Hope this will be helpfull for someone.

希望这对某人有帮助。

回答by monkrus

This solution fixed the error in Win10.

此解决方案修复了 Win10 中的错误。

Please install globally npm install -g node-pre-gyp

请全局安装 npm install -g node-pre-gyp