0
0

More than 1 year has passed since last update.

Yarn v2でworkspace-toolsプラグインをインストールした後、YarnのCLIでエラーが出るときの対処法

Last updated at Posted at 2021-10-25

エラーの詳細

Usage Error: This plugin cannot access the package referenced via typanion which is neither a builtin, nor an exposed entry (when initializing @yarnpkg/plugin-workspace-tools, defined in ~path/to/.yarnrc.yml)

Yarn v2でworkspace-toolsプラグインをインストールした後、YarnのCLIで何をやってもこのエラーが出て、先に進めなくなりました。

エラーが出るまでの再現

1. Yarn v2をインストールする

npm install -g yarn
cd ~/path/to/project
yarn set version berry
yarn set version 2.x

現時点(2021/10/22)では、yarn set version berryを実行するとYarn v3がインストールされます。最初から、yarn set version 2.xを実行したいところですが、Yarn v1でこれを実行するとエラーになるため、一度Yarn v3を経由する必要があります。

2. workspace-toolsプラグインをインストールする

yarn plugin import workspace-tools

このあとYarnのCLIで何をやっても上記のエラーが出るようになります。

対処法

上記のエラーが出たのは、インストールしたプラグインがYarn v3対応であったことが原因だと思われます。上記のエラーにはtypanion which is neither a builtin, nor an exposed entryという文言が含まれていましたが、現時点(2021/10/22)で最新版のworkspace-toolsの依存関係にはtypanionが含まれています。しかし、Yarn v2対応の中で最新版の依存関係にはtypanionが含まれていません。以上を踏まえると、Yarn v2対応のプラグインをインストールすれば解決できそうです。

1. プラグインをアンインストールする

rm .yarn/plugins/\@yarnpkg/plugin-workspace-tools.cjs 
.yarnrc.yml
- plugins:
-   path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
-   spec: "@yarnpkg/plugin-workspace-tools"

YarnのCLIはエラーが出て使えないため、一度プラグインを手動でアンインストールします。

2. Yarn v2対応のプラグインをインストールする

yarn plugin import https://github.com/yarnpkg/berry/raw/%40yarnpkg/plugin-workspace-tools/2.2.0/packages/plugin-workspace-tools/bin/%40yarnpkg/plugin-workspace-tools.js

yarn plugin import <name>では、残念ながらバージョンを指定することができません。実際、yarn plugin import workspace-tools@2.xなどを実行してみると、以下のようなエラーが出ます。仕方がないので、エラーの指示に従い、直接URLを指定してインストールします。

➤ YN0051: Couldn't find a plugin named "@yarnpkg/plugin-workspace-tools@2.x" on the remote registry. Note that only the plugins referenced on our website (https://github.com/yarnpkg/berry/blob/master/plugins.yml) can be referenced by their name; any other plugin will have to be referenced through its public url (for example https://github.com/yarnpkg/berry/raw/master/packages/plugin-typescript/bin/%40yarnpkg/plugin-typescript.js).

補足

指定するURLは以下の方法で調べられます。Yarn v2対応の他のプラグインをインストールするときの参考にしてください。

1. npmのVersionsタブでYarn v2対応の中での最新版を調べる
1.png

2. yarnkg/berryのリポジトリでプラグイン名とバージョンでタグを指定する
スクリーンショット 2021-10-25 0.33.28.png

3. プラグインのソースコードのページでrawデータのURLを取得する
スクリーンショット 2021-10-24 14.46.52.png

0
0
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
0
0