前言
这是一次前端项目构建失败的惨案,项目已经部署很久了,一直相安无事。因为开发更新了代码,在构建的时候报错:main.js: Cannot find module ‘core-js/modules/es.promise.finally’
09:59:30 yarn run v1.22.17
09:59:30 $ vue-cli-service build
09:59:30
09:59:30 ERROR Failed to compile with 1 error1:59:19 AM
09:59:30
09:59:30 error in ./src/main.js
09:59:30
09:59:30 Syntax Error: Thread Loader (Worker 0)
09:59:30 /home/jenkins/agent/workspace/form_uat/src/main.js: Cannot find module 'core-js/modules/es.promise.finally'
09:59:30 Require stack:
09:59:30 - /home/jenkins/agent/workspace/form_uat/node_modules/@vue/babel-preset-app/polyfillsPlugin.js
09:59:30 - /home/jenkins/agent/workspace/form_uat/node_modules/@vue/babel-preset-app/index.js
09:59:30 - /home/jenkins/agent/workspace/form_uat/node_modules/@vue/cli-plugin-babel/preset.js
09:59:30 - /home/jenkins/agent/workspace/form_uat/node_modules/@babel/core/lib/config/files/module-types.js
09:59:30 - /home/jenkins/agent/workspace/form_uat/node_modules/@babel/core/lib/config/files/configuration.js
09:59:30 - /home/jenkins/agent/workspace/form_uat/node_modules/@babel/core/lib/config/files/index.js
09:59:30 - /home/jenkins/agent/workspace/form_uat/node_modules/@babel/core/lib/index.js
09:59:30 - /home/jenkins/agent/workspace/form_uat/node_modules/babel-loader/lib/index.js
09:59:30 - /home/jenkins/agent/workspace/form_uat/node_modules/loader-runner/lib/loadLoader.js
09:59:30 - /home/jenkins/agent/workspace/form_uat/node_modules/loader-runner/lib/LoaderRunner.js
09:59:30 - /home/jenkins/agent/workspace/form_uat/node_modules/thread-loader/dist/worker.js
09:59:30 at Array.forEach (<anonymous>)
09:59:30
09:59:30
09:59:30 @ multi ./src/main.js
09:59:30
09:59:30 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
排查过程
- 因为jenkins是用K8S部署的而且我没参与部署,这里踩了不少的坑,首先看到报错想到的是core-js模块未安装。但是到服务器检查是有安装的
- 这时看到了一篇文章,就联想到可能是配置文件的问题,但是开发在本地构建是正常的,所以这个答案也是不成立的,还需要继续排查。参考文章:https://www.jianshu.com/p/6af4442cbbca
- 由于npm使用的是淘宝镜像,所以开发建议将镜像修改成官方镜像,还是同样的报错
原配置: yarn config set registry https://registry.npm.taobao.org/
新配置: yarn config set registry https://registry.yarnpkg.com/ - 最后想到清除yarn 全局 cache试一下,终于成功了
rm -rf /mnt/jenkins/yarn/v6
解决方案
删除jenkins目录下yarn 全局 cache ,删除后重新构建,让其重启拉取资源
rm -rf /mnt/jenkins/yarn/v6
文章来源:https://www.toymoban.com/news/detail-545032.html
总结
因为之前没接触过jenkins+yarn所以排查的时候相当小白,分析这次是因为core-js版本太旧导致的,希望本文对大家排查有帮助。文章来源地址https://www.toymoban.com/news/detail-545032.html
到了这里,关于记一次 jenkins 构建失败 “Cannot find module ‘core-js/modules/es.promise.finally‘”的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!