我有一个 node.js 应用程序,当我运行它时运行良好npm start
但是当我尝试构建它时,进程冻结了。这是我所看到的:
$ npm run build
> [email protected] /cdn-cgi/l/email-protection build /home/ppdevts4/public_html/reactsearch
> react-scripts build
Creating an optimized production build...
我可以将其放置 2 小时或 2 天,但它永远不会改变。
在服务器上,我可以看到 CPU 峰值约为 30%,RAM 约为 10%,输入/输出使用率约为 50%。所以看来资源不是问题。
我在 public_html 中发现了一个名为 error_log 的文件,并且在运行后没有向其中添加新条目npm run build
.
有建议如何调试吗?
我是 Node.js 新手。
谢谢,
菲尔
更新 ...
删除服务器限制后,脚本现在以错误结束。这是我在 .npm/_logs 文件夹中的 debug.log 中看到的内容:
0 info it worked if it ends with ok
1 verbose cli [ '/home/ppdevts4/bin/node', '/home/ppdevts4/bin/npm', 'run', 'build' ]
2 info using [email protected] /cdn-cgi/l/email-protection
3 info using [email protected] /cdn-cgi/l/email-protection
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected] /cdn-cgi/l/email-protection~prebuild: [email protected] /cdn-cgi/l/email-protection
6 info lifecycle [email protected] /cdn-cgi/l/email-protection~build: [email protected] /cdn-cgi/l/email-protection
7 verbose lifecycle [email protected] /cdn-cgi/l/email-protection~build: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected] /cdn-cgi/l/email-protection~build: PATH: /home/ppdevts4/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/ppdevts4/public_html/reactsearch/node_modules/.bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/cpanel/composer/bin:/home/ppdevts4/.local/bin:/home/ppdevts4/bin
9 verbose lifecycle [email protected] /cdn-cgi/l/email-protection~build: CWD: /home/ppdevts4/public_html/reactsearch
10 silly lifecycle [email protected] /cdn-cgi/l/email-protection~build: Args: [ '-c', 'react-scripts build' ]
11 silly lifecycle [email protected] /cdn-cgi/l/email-protection~build: Returned: code: 1 signal: null
12 info lifecycle [email protected] /cdn-cgi/l/email-protection~build: Failed to exec build script
13 verbose stack Error: [email protected] /cdn-cgi/l/email-protection build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/home/ppdevts4/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:209:13)
13 verbose stack at ChildProcess.<anonymous> (/home/ppdevts4/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:209:13)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid [email protected] /cdn-cgi/l/email-protection
15 verbose cwd /home/ppdevts4/public_html/reactsearch
16 verbose Linux 3.10.0-962.3.2.lve1.5.25.10.el7.x86_64
17 verbose argv "/home/ppdevts4/bin/node" "/home/ppdevts4/bin/npm" "run" "build"
18 verbose node v12.9.1
19 verbose npm v6.12.0
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] /cdn-cgi/l/email-protection build: `react-scripts build`
22 error Exit status 1
23 error Failed at the [email protected] /cdn-cgi/l/email-protection build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
另一个帖子说npm install react-scripts --save
可能会修复它,但之后的错误日志是相同的。
有什么建议如何修复此错误?
更新于 2019 年 10 月 14 日
我在 AWS 上创建了一个具有 8 个 CPU 和 32GB RAM 的 t3.s 实例,它给出了类似的错误,因此这似乎不是由内存不足引起的。
这是日志:
0 info it worked if it ends with ok
1 verbose cli [ '/home/ec2-user/bin/node', '/home/ec2-user/bin/npm', 'run', 'build' ]
2 info using [email protected] /cdn-cgi/l/email-protection
3 info using [email protected] /cdn-cgi/l/email-protection
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected] /cdn-cgi/l/email-protection~prebuild: [email protected] /cdn-cgi/l/email-protection
6 info lifecycle [email protected] /cdn-cgi/l/email-protection~build: [email protected] /cdn-cgi/l/email-protection
7 verbose lifecycle [email protected] /cdn-cgi/l/email-protection~build: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected] /cdn-cgi/l/email-protection~build: PATH: /home/ec2-user/nodejs/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/ec2-user/public_html/reactsearch/node_modules/.bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/.local/bin:/home/ec2-user/bin
9 verbose lifecycle [email protected] /cdn-cgi/l/email-protection~build: CWD: /home/ec2-user/public_html/reactsearch
10 silly lifecycle [email protected] /cdn-cgi/l/email-protection~build: Args: [ '-c', 'react-scripts build' ]
11 silly lifecycle [email protected] /cdn-cgi/l/email-protection~build: Returned: code: 1 signal: null
12 info lifecycle [email protected] /cdn-cgi/l/email-protection~build: Failed to exec build script
13 verbose stack Error: [email protected] /cdn-cgi/l/email-protection build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/home/ec2-user/nodejs/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:326:16)
13 verbose stack at EventEmitter.emit (events.js:209:13)
13 verbose stack at ChildProcess.<anonymous> (/home/ec2-user/nodejs/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:209:13)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid [email protected] /cdn-cgi/l/email-protection
15 verbose cwd /home/ec2-user/public_html/reactsearch
16 verbose Linux 4.14.146-93.123.amzn1.x86_64
17 verbose argv "/home/ec2-user/bin/node" "/home/ec2-user/bin/npm" "run" "build"
18 verbose node v12.9.1
19 verbose npm v6.10.2
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] /cdn-cgi/l/email-protection build: `react-scripts build`
22 error Exit status 1
23 error Failed at the [email protected] /cdn-cgi/l/email-protection build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]