npm start 和 npm run build 失败,报错为 npm ERR!code ELIFECYCLE。

3

我已经遇到这个问题3天了。以前偶尔会出现这个错误,但只要运行一些故障排除命令,它就会开始正常工作,现在npm start根本无法工作,并且我不断收到此错误。

主机详细信息:

Ubuntu server 18.04 LTS
Node v8.10.0
npm 6.10.2

我按照以下顺序进行了尝试:
rm -rf node_modules
rm package-lock.json
npm install -g npm
npm install
npm start
sudo npm start

然后:

npm install create-react-app
npm install react-scripts
node node_modules/react-scripts/scripts/start.js

曾尝试删除整个文件夹,创建目录并重新从github拉取代码。只是为了测试 chown ubuntu project_folder

什么都没有起作用。

该应用程序是使用create-react-app创建的,在我的桌面电脑和笔记本电脑上运行良好。

Starting the development server...

The build failed because the process exited too early. This probably means the system ran out of memory or someone called `k
ill -9` on the process.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! REDACTED@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the REDACTED@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ubuntu/.npm/_logs/2019-08-05T14_02_01_500Z-debug.log

/home/ubuntu/.npm/_logs/2019-08-05T14_02_01_500Z-debug.log的数据:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@6.10.2
3 info using node@v8.10.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle REDACTED@0.1.0~prestart: REDACTED@0.1.0
6 info lifecycle REDACTED@0.1.0~start: REDACTED@0.1.0
7 verbose lifecycle REDACTED@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle REDACTED@0.1.0~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/hom
e/ubuntu/code/bf_dev/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/ga
mes:/snap/bin
9 verbose lifecycle REDACTED@0.1.0~start: CWD: /home/ubuntu/code/bf_dev
10 silly lifecycle REDACTED@0.1.0~start: Args: [ '-c', 'react-scripts start' ]
11 silly lifecycle REDACTED@0.1.0~start: Returned: code: 1  signal: null
12 info lifecycle REDACTED@0.1.0~start: Failed to exec start script
13 verbose stack Error: REDACTED@0.1.0 start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:326:16
)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55
:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid REDACTED@0.1.0
15 verbose cwd /home/ubuntu/code/bf_dev
16 verbose Linux 4.15.0-1044-aws
17 verbose argv "/usr/bin/node" "/usr/local/bin/npm" "start"
18 verbose node v8.10.0
19 verbose npm  v6.10.2
20 error code ELIFECYCLE
21 error errno 1
22 error REDACTED@0.1.0 start: `react-scripts start`
22 error Exit status 1
23 error Failed at the REDACTED@0.1.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

任何帮助都非常感激。

我不确定你是从何处得到使用CRA语法创建React项目的参考资料。如果你已经在console中运行了“npm install -g create-react-app”并使用“npx create-react-app [app-name]”创建了你的项目,则无需单独安装“react-scripts”。只需执行“npm start”即可完成操作。 - bijayshrestha
2个回答

1
我已经多次遇到这个错误。 在运行npm install create-react-app之后,使用命令create-react-app检查是否已安装create-react-app。它会告诉你create-react-app未被安装,因为你没有在项目所在的文件夹中安装create-react-app。 你只需要在正确的目录中安装create-react-app。或者你可以全局安装它,使用如下命令:

npm install -g create-react-app

如果你不想全局安装它,请前往项目所在的文件夹,然后在该文件夹中安装create-react-app。

基本上,你遇到这个错误是因为create-react-app未在你的目录中安装。 这应该可以解决你的问题。

如果这不能帮助你,你可以尝试以下操作:

注意:你的机器上需要Node >= 8.10和npm >= 5.6。 前往所需的文件夹。 然后,

ngx create-react-app my-app
cd my-app
npm start

这是在create react app的官方文档中,所以应该有效。

是的,我运行了sudo npm install -g create-react-app。仍然出现错误。 - boostedd
在使用 npx create-react-app test 创建新项目目录后,运行 npm start 仍会出现相同的错误。 - boostedd
create-react-app 返回帮助文本,我在正确的目录中。这个项目在另外两台机器上都没有问题。 - boostedd
Ubuntu服务器18.04 LTS Node v8.10.0 npm 6.10.2我的桌面电脑运行的是Arch Linux。node v10.16.0,npm 6.10.1可以很好地运行该项目。尽管如此,这在过去在Ubuntu服务器上也能够正常工作。 - boostedd
1
据我所知,这应该可以正常工作。我建议尝试升级 Node 到更高的版本,看是否能解决问题。Ngx 应该可以与你当前的 Node 版本兼容。我不知道为什么在你的计算机上会出现这个问题。 - Amrit Subedi
显示剩余7条评论

0

感谢大家的回复。看起来是用户错误。

根据这个帖子更新了Node.js:如何更新Node.js?

项目加载得很好,我猜测Arch在软件方面处于前沿,而Ubuntu仓库落后了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接