VueCli项目执行npm run build报ELIFECYCLE错误无法构建如何解决
VueCli项目执行npm run build构建失败排查解决
问题现象
我的前端项目使用VueCli进行开发,当前需要将存放于远程服务器的项目部署至正式服务器,首先执行npm run build命令打包前端代码,但反复出现如下错误,无法完成构建:
npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! mobile-h5@0.1.0 build: `vue-cli-service build` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the mobile-h5@0.1.0 build 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! /Users/daisywu/.npm/_logs/2021-09-24T06_13_06_000Z-debug.log
我已尝试删除package-lock.json文件和node_modules文件夹,执行npm cache clean --force清理npm缓存,再重新执行npm install安装依赖,依旧无法完成构建。
debug.log日志内容如下:
0 info it worked if it ends with ok 1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ] 2 info using npm@6.14.9 3 info using node@v14.15.3 4 verbose run-script [ 'prebuild', 'build', 'postbuild' ] 5 info lifecycle mobile-h5@0.1.0~prebuild: mobile-h5@0.1.0 6 info lifecycle mobile-h5@0.1.0~build: mobile-h5@0.1.0 7 verbose lifecycle mobile-h5@0.1.0~build: unsafe-perm in lifecycle true 8 verbose lifecycle mobile-h5@0.1.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/daisywu/Documents/mobile-h5/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin 9 verbose lifecycle mobile-h5@0.1.0~build: CWD: /Users/daisywu/Documents/mobile-h5 10 silly lifecycle mobile-h5@0.1.0~build: Args: [ '-c', 'vue-cli-service build' ] 11 silly lifecycle mobile-h5@0.1.0~build: Returned: code: 1 signal: null 12 info lifecycle mobile-h5@0.1.0~build: Failed to exec build script 13 verbose stack Error: mobile-h5@0.1.0 build: `vue-cli-service build` 13 verbose stack Exit status 1 13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16) 13 verbose stack at EventEmitter.emit (events.js:315:20) 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 ChildProcess.emit (events.js:315:20) 13 verbose stack at maybeClose (internal/child_process.js:1048:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) 14 verbose pkgid mobile-h5@0.1.0 15 verbose cwd /Users/daisywu/Documents/mobile-h5 16 verbose Darwin 20.3.0 17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build" 18 verbose node v14.15.3 19 verbose npm v6.14.9 20 error code ELIFECYCLE 21 error errno 1 22 error mobile-h5@0.1.0 build: `vue-cli-service build` 22 error Exit status 1 23 error Failed at the mobile-h5@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 ]
解决方案
经排查,问题原因为Node.js运行内存不足,按如下步骤操作即可解决:
- 打开项目根目录下的
package.json文件 - 修改build命令配置为:
"build": "node --max_old_space_size=4096 node_modules/@vue/cli-service/bin/vue-cli-service.js build --mode development"
- 修改完成后重新执行
npm run build即可正常构建。
内容的提问来源于stack exchange,提问作者Chieh YU WU
相关产品推荐
相关产品推荐

