LoginSignup
8
5

More than 5 years have passed since last update.

Requires Babel "^7.0.0-0", but was loaded with "6.26.3".の解決方法

Posted at

はじめに

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/corebabel-coreは別物なのか?(よくわかってない
でも、warning出るの気持ち悪いので入れよう。

yarn add -D babel-core@7.0.0-bridge.0

以上でなんとか解決した。
babel-core@7.0.0-bridge.0を入れたのは、ここで入れてみろとあったのと、7.0.0の最新がこれだったから。

8
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
8
5