某个版本之前pnpm
都是通过HTTP安装托管在git源上的npm包的,然而似乎某个版本开始就有可能采取SSH连接的方式。然而,SSH需要SSH Key才可以连接到git源(仅以Github为例),这样的策略会导致在一些CI上无法安装依赖(例如Vercel),得到这样的错误:
Cloning into '/vercel/.local/share/pnpm/store/v3/tmp/.....'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
这个问题碰到很久了。观察发现pnpm
在安装时,会随机地从HTTP或Git拉取包,所以每一次安装依赖以后,Git包的来源都可能发生变化。所以之前都是反复安装然后最终得到从codeload.github.com
加载的结果时再上传lockfile
。是的,很粗暴。
今天终于想彻底地修一下这个问题。机缘巧合找到了这么一篇GIST,引用如下:
# npm using https for git
git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://
# npm using git for https
git config --global url."git@github.com:".insteadOf https://github.com/
git config --global url."git://".insteadOf https://
试了一下果然管用,爽到。
当然也可能是正好随机到codeload了?有待观察。
所以我之前又翻pnpm
文档又翻npm
文档试图找到一个config或者cli option来解决问题实在走错路了,其实就和如何配置pnpm
访问git
时的代理一样,从git
下手就完事了😀
封面图像 by Pete Linforth from Pixabay
Comments NOTHING