问题 使用jenkins对一个前端项目进行打包,每次打包都出现 file-saver
超时(TIMEOUT)问题。即使将yarn依赖源改成国内都解决不了。
1 2 3 error An unexpected error occurred: "https://raw.githubusercontent.com/eligrey/FileSaver.js/e865e37af9f9947ddcced76b549e27dc45c1cb2e/package.json: ETIMEDOUT" . info If you think this is a bug, please open a bug report with the information provided in "/var/jenkins_home/workspace/frontend_k8s/yarn-error.log" . info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command .
鉴于国内对GITHUB访问时断时续的情况,如果打包时还是从GITHUB进行下载,那么这个问题就会一直出现。
那么,在已经将yran源改成国内的情况下,为何还会出现从 GITHUB 下载的情况呢? 而且项目中 FileSaver 使用的 代码形式的引入,没有进行依赖配置。
排查 为了排查问题,我先在本机电脑上使用 VPN,然后执行 yarn install
看下 yarn.lock
情况。
在命令成功执行后,打开 yarn.lock
文件,搜索 file-saver
找到了原因。
原来是程序中使用了 jspdf
,而这个组件依赖 file-saver
,而且指定从 GITHUB 下载。
至此总算找到原因了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 jspdf@^1.5.3: version "1.5.3" resolved "https://registry.npmmirror.com/jspdf/-/jspdf-1.5.3.tgz#..." integrity sha512-J9X76xnncMw+wIqb15HeWfPMqPwYxSpPY8yWPJ7rAZN/ZDzFkjCSZObryCyUe8zbrVRNiuCnIeQteCzMn7GnWw== dependencies: canvg "1.5.3" file-saver eligrey/FileSaver.js#1.3.8 html2canvas "1.0.0-alpha.12" omggif "1.0.7" promise-polyfill "8.1.0" stackblur-canvas "2.2.0" file-saver@1.3.8, "file-saver@github:eligrey/FileSaver.js#1.3.8" : version "1.3.8" resolved "https://codeload.github.com/eligrey/FileSaver.js/tar.gz/e865e37af9f9947ddcced76b549e27dc45c1cb2e"
解决 在 package.json
文件中,添加 resolutions
:
1 2 3 4 5 { "resolutions" : { "**/file-saver" : "^2.0.5" } }
示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 { "name" : "xxx" , "version" : "1.0.2" , "private" : true , "author" : "8080@gmail.com" , "scripts" : { } , "dependencies" : { } , "devDependencies" : { } , "resolutions" : { "**/file-saver" : "^2.0.5" } , }
然后删除 yarn.lock
后,重新执行:yarn install
.