Vercel 部署失敗,Host key verification failed

[Vercel] Vercel 部署失敗,Host key verification failed 解決方式

前幾天在用 sideproject,透過 vercel 部署,前幾次都成功,直到有次部署翻船了,出現錯誤訊息 Host key verification failed
這篇紀錄詳細解決方式、問題發生原因

完整錯誤訊息如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Cloning github.com/Hazelwu2/CoolProposal (Branch: test/cicd, Commit: b868754)
Cloning completed: 464.111ms
Looking up build cache...
Build Cache not found
Running "vercel build"
Vercel CLI 25.1.0 build (beta) — https://vercel.com/feedback
Installing dependencies...
yarn install v1.22.17
warning package.json: No license field
warning ../package.json: No license field
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
warning [email protected]: No license field
[1/4] Resolving packages...
[2/4] Fetching packages...
error Command failed.
Exit code: 128
Command: git
Arguments: ls-remote --tags --heads ssh://[email protected]/ethereumjs/ethereumjs-abi.git
Directory: /vercel/path0/f2e
Output:
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Error! Command "yarn install" exited with 128

Error: Command "vercel build" exited with 1

問題

1
2
Host key verification failed.
fatal: Could not read from remote repository.

看到 Log 上面兩行,本以為是 ssh key 設定錯誤導致權限不足,做了幾個改變,像是邀請其他人到我的 github 專案協作,但問題依舊沒有解決!

耐心重看一遍 Log,找到了癥結點
Log訊息出現

1
Arguments: ls-remote --tags --heads ssh://gi[email protected]/ethereumjs/ethereumjs-abi.git

在我的案例中安裝了 ethers.js 套件,也有另外安裝依賴的套件 ethereumjs-abi
在安裝 ethereumjs-abi 發生問題!查了 Google 發現超多人有這個案例,只要透過 CICD 部署,不管是 Vercel、Gitlab 等等部署工具,只要用 npm install 跑過,部署就會出現以上的問題

解決方式

yarn.lockpackage.lock 移除,並改用 yarn 安裝,不要使用 npm install

之所以會發生此問題,我另外一位協作者是 Windows 系統,電腦沒有安裝 Yarn,為了求快速是用 npm 來安裝套件,沒想到就這樣翻船了…
結論:同一專案協作者還是要說好,使用同一套的系統,yarn或npm

另一個解決方式是,開啟 yarn.lockpackage.lock,找到 ethereumjs-abi,將 https:// 取代 git+ssh://

1
2
3
4
// before
"resolved": "https://registry.npmjs.org/ethereumjs-abi/-/ethereumjs-abi-0.6.8.tgz"
// after
"resolved": "git+ssh://[email protected]/ethereumjs/ethereumjs-abi.git#ee3994657fa7a427238e6ba92a84d0b529bbcde0"

Reference


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!