最近公司的前端项目有些要迁移到K8S上,前几天已经通过Gitee跟Jenkins构建打包好镜像上传到k8s上了,今天他们做了一些更新内容后,Jenkins上一直构建失败,到90%的时候就终止了。问了前端的同事,他们说这其实已经打包好了,是传到别的目录的时候的报错了。虽然对前端知识不懂,但是知道他们这是在胡扯,构建时候明明写着只到90%,还说是成功。
然后想知道哪个指令可以详细输出报错信息的,问了下另一个前端小哥哥,他说这个要修改build文件了。然后他在本地给我构建了一遍,他那里是成功的,然后让我将node_modules删了,不要用npm install,替换成yarn,结果yarn时候报错
'''
<pre class="console-output" style="box-sizing: border-box; white-space: pre-wrap; overflow-wrap: break-word; margin: 0px; color: rgb(51, 51, 51); font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">[2/4] Fetching packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
error An unexpected error occurred: "https://registry.npm.taobao.org/antd-mobile/download/antd-mobile-2.3.1.tgz: unexpected end of file".
info If you think this is a bug, please open a bug report with the information provided in "/***/jenkins/workspace/web-front-test/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Build step 'Execute shell' marked build as failure
Finished: FAILURE</pre>
'''
指定了淘宝的源也是报错
'''
yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global
yarn config set ignore-engines true
'''
因为Jenkins本地的node的版本跟他们的版本不太一样,所以建议我将Jenkins的版本换了。但是我没有权限,也懒得去申请了。于是继续看,直到看到说将cache删了,跟package-lock.json也删了,然后重新安装
就是后面改成:
'''
npm -v
npm cache clean --force
rm -rf node_modules
rm -rf package-lock.json
npm install
npm run build
'''
然后重新构建,就成功了。