起因:
突然收到流水线构建报错,Coundn't find package...
加了新包导致的吗?但是最近也没有改啥配置。另外最近也有加新包qrcode,也没出问题。
问题出在哪?
大胆假设
- 网络问题——这个概率不大。
- npm源问题——极有可能。
小心求证
-
安装试验
安装
qrcode,成功!$ npm i qrcode --registry=http://ip:4873 npm WARN aaa@1.0.0 No description npm WARN aaa@1.0.0 No repository field. + qrcode@1.5.3 added 30 packages from 24 contributors and audited 32 packages in 5.984s 2 packages are looking for funding run `npm fund` for details found 0 vulnerabilities安装
compress.js,果然失败了!$ npm i compress.js --registry=http://ip:4873 npm ERR! code E404 npm ERR! 404 Not Found - GET http://ip:4873/compress.js - no such package available npm ERR! 404 npm ERR! 404 'compress.js@^1.2.2' is not in the npm registry. npm ERR! 404 You should bug the author to publish it (or use the name yourself!) npm ERR! 404 npm ERR! 404 Note that you can also install from a npm ERR! 404 tarball, folder, http url, or git url.那定是内网源的出了问题。
-
修改配置
ChatGPT查下Verdaccio有哪些配置,查到
uplinks.npmjs.url配置项可配置代理到官方 npm registry,或其他 npm registry。 一顿操作找到Verdaccio配置位置,修改https://registry.npm.taobao.org为https://registry.npmmirror.com/。重启下Verdaccio。
-
验证猜想
再安装
compress.js,成功!$ npm i compress.js --registry=http://ip:4873 npm WARN aaa@1.0.0 No description npm WARN aaa@1.0.0 No repository field. + compress.js@1.2.2 updated 1 package and audited 32 packages in 1.619s
后记
访问https://registry.npm.taobao.org会自动重定向到新的源,为啥qrcode包可以而compress.js不行呢,有掘友知否?
更新
qrcode包可以是因为有缓存,verdaccio优先读取缓存的。因此换了uplinks,最好把verdaccio的缓存目录清空,当然也可遇到了针对性处理,否则可能造成有些包无法下载(包的package.json缓存了旧的uplinks链接,导致无法下载)。
$ pwd
/data/verdaccio/storage/data/compress.js
$ ll
总用量 52
-rw-r--r-- 1 10001 65533 50373 5月 23 10:25 package.json
$ cd ../qrcode
$ ll
总用量 680
-rw-r--r-- 1 10001 65533 145424 5月 23 15:20 package.json
-rw-r--r-- 1 10001 65533 183419 9月 24 2020 qrcode-1.2.0.tgz
-rw-r--r-- 1 10001 65533 232765 10月 19 2021 qrcode-1.4.4.tgz
-rw-r--r-- 1 10001 65533 77496 4月 4 2023 qrcode-1.5.1.tgz
-rw-r--r-- 1 10001 65533 49838 4月 23 2023 qrcode-1.5.3.tgz