31
5

More than 5 years have passed since last update.

yarnコマンドで 404 Not Found に遭遇したときの対処法

Posted at

yarn global addコマンドでツールがインストール出来ない状況に陥ったのですが、解決したので解決方法をメモしておきます。

トラブル内容

yarnでツールをインストールしようとしたときにトラブルに遭遇しました。

$ yarn global add @vue/cli
yarn global v1.13.0
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/har-validator/-/har-validator-5.1.2.tgz: Request failed \"404 Not Found\"".
info If you think this is a bug, please open a bug report with the information provided in "/Users/username/.config/yarn/global/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.

har-validator-5.1.2404 Not Found ・・・

原因と解説

今回たまたま引っかかったのは har-validator パッケージで、該当リポジトリのissueが少しばかり盛り上がっています。

何が起きたかというと、

  1. har-validator の作者が バージョン 5.1.1 をpublish
  2. har-validator の作者が バージョン 5.1.2 をpublish
  3. このタイミングで私のPCに har-validator 5.1.2yarn.lockに記録される
  4. har-validator の作者がバージョン 5.1.2 を unpublish した
  5. yarn.lock のバージョン固定により har-validator 5.1.2 をダウンロードしようとするが存在しない

publish したパッケージやライブラリに問題があった場合は、そのバージョンを unpublish するだけではダメで、
rollback したバージョンをさらに publish しておくのが正しい対処になります。

先ほどのバージョンの例だと、以下が正しい対処です。

  1. 5.1.1 を publish
  2. 5.1.2 を publish (取り消したいバージョン)
  3. 5.1.2 を unpublish
  4. 5.1.1 の内容を 5.1.3 として publish

yarn global にも yarn.lock はしっかりと作成されているため、そこに存在しないバージョンが記録されているのが原因でした。

解決策

yarn.lock の更新または再作成をします。

更新

yarn global upgrade

再作成

rm ~/.config/yarn/global/yarn.lock

yarn globalではない、個別のリポジトリの場合でも基本的には対処は同じで、
yarn.lockファイルを更新すれば良いです。

また、 npm を使っている場合でも同じことが起こり得ます。
その場合は package-lock.json を更新するか再作成しましょう。

31
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
5