1.问题描述:
前端是vue项目,打包和打镜像的时候,本地没问题,jenkins物理机打流水线也没问题,但是到容器云平台使用自带的流水线打包打镜像的时候,就报错了。上次成功上线的代码再打一遍仍然报错,由此可以肯定,不是代码导致的打包失败,所以就剩下是网络或者配置的问题了。
报错信息:
process.env.NODE_ENV production - Building for production... events.js:186 throw er; // Unhandled 'error' event ^ Error: This socket has been ended by the other party at Socket.writeAfterFIN [as write] (net.js:441:14) at PoolWorker.writeJson (/home/node/bob_front_web/node_modules/thread-loader/dist/WorkerPool.js:122:20) at PoolWorker.run (/home/node/bob_front_web/node_modules/thread-loader/dist/WorkerPool.js:104:10) at WorkerPool.distributeJob (/home/node/bob_front_web/node_modules/thread-loader/dist/WorkerPool.js:332:18) at runQueue (/home/node/bob_front_web/node_modules/neo-async/async.js:8099:9) at processTicksAndRejections (internal/process/task_queues.js:75:11) Emitted 'error' event on Socket instance at: at emitErrorNT (net.js:1325:8) at processTicksAndRejections (internal/process/task_queues.js:80:21) { code: 'EPIPE' } npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! bob-web@2.6.0 build: `vue-cli-service build` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the bob-web@2.6.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! /root/.npm/_logs/2022-10-10T01_07_49_577Z-debug.log error building image: error building stage: failed to execute command: waiting for process to exit: exit status 1
2.原因分析
1.有可能是package.json包里引入依赖的时候写的是最新的包,不是具体的版本号导致的,官方一更新,拉下来最新的包有问题。但是如果是这样的话,本地和jenkins物理机也应该打包失败啊,所以排除。
2.再回头看报错的信息里有PoolWorker.writeJson之类的字眼,有可能是多线程打包导致的顺序不对,导致最终失败。
经百度发现,vue.config.js里有一个配置parallel可以控制是单线程还是多线程打包,设置为false就行了。
module.exports={ publicPath: '/', lintOnSave: true, productionSourceMap: false, transpileDependencies: [/node_modules/], parallel: false,//为true时使用多进程进行打包提高构建速度 chanWebpack: (config)=>{ //忽略的打包文件 config.externals({ 'vue-router': 'VueRouter', vuex: 'Vuex' }) const entry = config.entry('app') entry.add('babel-polyfill').end() entry.add('classlist-polyfill').end() }