posted: 2018/04/21
babel@7の環境でjest使う時に頑張る必要がある話
babelの7系を利用しつつjestを利用すると、こんなエラーが出てしまう。
Requires Babel "^7.0.0-0", but was loaded with "6.26.0". 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.
jestとbabel@7の相性があまり良くないようで、
@babel/core
, babel-core
をどっちも入れたりbabel-jest
を使わないといけないhttps://facebook.github.io/jest/docs/en/getting-started.html#using-babel
https://github.com/facebook/jest/issues/4748
https://github.com/facebook/jest/issues/4748
あんまり裏側は追ってないが、とりあえずこんな感じ
$ npm install babel-core@^7.0.0-0 @babel/core babel-jest regenerator-runtime
一応これで動くはずだが、動かない場合はbabel-jestを挟むと動く場合がありそう。
"transform": {
"^.+\\.jsx?$": "babel-jest"
},