はじめに
webpack x babelでJestを導入して、
yarn run test
を実行しようとしたら以下エラーが出て若干ハマったのでメモ。
Requires Babel "^7.0.0-0", but was loaded with "6.26.3".
If you are sure you have a compatible version of @babel/core,
it is likely that something in your build process is loading the wrong version.
Inspect the stack trace of this error to look for the first entry that
doesn't mention "@babel/core" or "babel-core" to see what is calling Babel.
解決前の状態
package.json
の解決前の状態は以下。(devDependencies
部分のみ記載
@babel/core
は7以上じゃねーか。なんでありもしない6.26.3
を参照すんだよ。。
package.json
"devDependencies": {
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.1",
"babel-loader": "^8.0.5",
"jest": "^23.6.0",
"webpack": "^4.29.6",
"webpack-cli": "^3.3.0"
},
解決方法
いろいろ調べた結果、babel-jest
が必要らしい。
(JestのGetting Startedにはそんな事書いてなかった、、、
なので、
yarn add babel-jest
で入れる。
すると、
warning " > babel-jest@23.6.0" has unmet peer dependency "babel-core@^6.0.0 || ^7.0.0-0".
とwarningがでた。@babel/core
とbabel-core
は別物なのか?(よくわかってない
でも、warning出るの気持ち悪いので入れよう。
yarn add -D babel-core@7.0.0-bridge.0
以上でなんとか解決した。
babel-core@7.0.0-bridge.0
を入れたのは、ここで入れてみろとあったのと、7.0.0の最新がこれだったから。