npm run build freezes - how to debug this?
npm run build freezes - how to debug this?
我有一个使用node.js的应用程序,当我使用npm start
运行时正常工作,但是当我尝试构建它时进程会冻结。这是我看到的内容:\n
$ npm run build > reactsearch@0.1.0 build /home/ppdevts4/public_html/reactsearch > react-scripts build 创建一个优化的生产构建...
\n我可以让它运行2个小时或2天,但它从未发生变化。\n在服务器上,我可以看到CPU峰值约为30%,RAM峰值约为10%,输入/输出使用率约为50%。所以资源似乎不是问题。\n我在public_html中找到了一个名为error_log的文件,在我运行npm run build
之后它没有添加任何新条目。\n请问有什么建议如何调试这个问题吗?\n我对node.js还不熟悉。\n谢谢,\nPhil\n更新...\n在删除服务器限制后,脚本现在以错误结束。这是我在.npm/_logs文件夹中的debug.log中看到的内容:\n
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 npm@6.12.0 3 info using node@v12.9.1 4 verbose run-script [ 'prebuild', 'build', 'postbuild' ] 5 info lifecycle reactsearch@0.1.0~prebuild: reactsearch@0.1.0 6 info lifecycle reactsearch@0.1.0~build: reactsearch@0.1.0 7 verbose lifecycle reactsearch@0.1.0~build: unsafe-perm in lifecycle true 8 verbose lifecycle reactsearch@0.1.0~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 reactsearch@0.1.0~build: CWD: /home/ppdevts4/public_html/reactsearch 10 silly lifecycle reactsearch@0.1.0~build: Args: [ '-c', 'react-scripts build' ] 11 silly lifecycle reactsearch@0.1.0~build: Returned: code: 1 signal: null 12 info lifecycle reactsearch@0.1.0~build: Failed to exec build script 13 verbose stack Error: reactsearch@0.1.0 build: `react-scripts build` 13 verbose stack Exit status 1 13 verbose stack at EventEmitter.(/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. (/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 reactsearch@0.1.0 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 reactsearch@0.1.0 build: `react-scripts build` 22 error Exit status 1 23 error Failed at the reactsearch@0.1.0 build script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 1, true ]
\n另一篇帖子说npm install react-scripts --save
可能会修复它,但错误日志之后还是一样的。\n有什么建议如何修复这个错误吗?\n更新于2019年10月14日\n我在AWS上创建了一个有8个CPU和32GB RAM的t3.s实例,它给出了一个类似的错误,所以看起来这不是由于内存不足引起的。\n这是日志内容:\n
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 npm@6.10.2 3 info using node@v12.9.1 4 verbose run-script [ 'prebuild', 'build', 'postbuild' ] 5 info lifecycle reactsearch@0.1.0~prebuild: reactsearch@0.1.0 6 info lifecycle reactsearch@0.1.0~build: reactsearch@0.1.0 7 verbose lifecycle reactsearch@0.1.0~build: unsafe-perm in lifecycle true 8 verbose lifecycle reactsearch@0.1.0~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 reactsearch@0.1.0~build: CWD: /home/ec2-user/public_html/reactsearch 10 silly lifecycle reactsearch@0.1.0~build: Args: [ '-c', 'react-scripts build' ] 11 silly lifecycle reactsearch@0.1.0~build: Returned: code: 1 signal: null 12 info lifecycle reactsearch@0.1.0~build: Failed to exec build script 13 verbose stack Error: reactsearch@0.1.0 build: `react-scripts build` 13 verbose stack Exit status 1 13 verbose stack at EventEmitter.(/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. (/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 reactsearch@0.1.0 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 reactsearch@0.1.0 build: `react-scripts build` 22 error Exit status 1 23 error Failed at the reactsearch@0.1.0 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 run build freezes - how to debug this?
最近在运行apt-get upgrade
之后遇到了相同的问题。我重新启动了控制台,然后一切都正常工作了。
原因:
- `apt-get upgrade`命令可能会更新操作系统相关的软件包,这可能导致与npm命令相关的某些依赖项出现冲突或不兼容的情况。
- 运行npm命令时,可能会占用大量的系统资源,尤其是在进行构建操作时。如果系统资源不足或被其他进程占用,可能会导致npm命令冻结。
解决方法:
- 尝试重新启动控制台或终端窗口,以确保任何占用的系统资源被释放。
- 确保操作系统和相关软件包是最新的,可以运行apt-get upgrade
或相应的系统更新命令来更新系统。
- 检查npm命令的依赖项是否与操作系统的更新版本不兼容。可以尝试更新npm或相关依赖项的版本,以解决冲突。
- 检查系统资源的使用情况,确保有足够的可用资源供npm命令使用。可以使用系统监控工具或任务管理器来检查资源使用情况。
- 如果问题仍然存在,可以尝试使用npm cache clean
命令清除npm的缓存,并重新运行构建命令。
希望以上解决方案能够帮助您解决npm run build冻结的问题。如果问题仍然存在,请尝试在npm社区或相关论坛上寻求帮助,以获得更多的支持和解决方案。