はじめに
今回はyarn add webpack
でエラーが発生しましたので,それの対処法を記述したいと思います.
(yarn ver 1.7.0)
webpack追加で発生したエラー
以下が実際に発生したエラー出力です.
$ yarn add webpack
yarn add v1.7.0
[1/4] Resolving packages...
[2/4] Fetching packages...
error enhanced-resolve@4.0.0: The engine "node" is incompatible with this module. Expected version ">=6.11.5".
error Found incompatible module
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
同じようなエラーが無いか検索すると,やはり同じような症状が発生した事例を発見.
なんかバージョンがだめっぽい.
バージョンを変えるのがベストとコメントしているので,それに従うことに.
バージョン指定方法
yarn add package
に対してバージョンを指定するには以下のように@のあとにバージョンを記述すればいい.
$ yarn add package@2.12.2
エラー対処方法
本題のwebpackのバージョンを指定してエラーを回避してみる.
今回バージョンは3.3.0とした
$ yarn add webpack@3.3.0
yarn add v1.7.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.4: The platform "linux" is incompatible with this module.
info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 194 new dependencies.
info Direct dependencies
エラーが出力されず,成功していることがわかる.
また,yarn add webpack-dev-server
についても同じエラーが起きたが,同様の対処法で回避できる.
まとめ
yarn add webpack
のエラーの対処法について記述した.
他のパッケージ追加時のエラーについてもバージョン指定で
回避できるかもしれないので,迷った際はぜひバージョン指定をしてほしい.