LoginSignup
51
24

More than 3 years have passed since last update.

nuxtでjestするとbabel-coreを見つけてくれない

Last updated at Posted at 2019-10-15

御託はいいから解決してくれ

babel-core@bridgeというパッケージを入れればOK

yarn add -D babel-core@bridge

何が起こっていたか

test時に vue-jest というパッケージが @babel/core ではなく、 babel-core を参照し続けている状態みたい。
下記のように、cannot find module 'babel-core' というエラーを吐き出してしまいます。

 FAIL  test/index.test.js
  ● Test suite failed to run

    Cannot find module 'babel-core'

      at _load_babelCore (node_modules/babel-jest/build/index.js:17:49)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.134s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

Process finished with exit code 1

babel-core@bridgeって何

babel-bridge公式にはこのように書いていました。

babel-bridge
This repo holds what we're calling a "bridge" package that is meant to ease the transition for libraries that use "babel-core" as a peer dependency for Babel 6.

The issue with Babel 7's transition to scopes is that if a package depends on Babel 6, they may want to add support for Babel 7 alongside. Because Babel 7 will be released as @babel/core instead of babel-core, maintainers have no way to do that transition without making a breaking change. e.g.

babelは7系から@babel/coreという名前でリリースされたので、babel 6系に依存したパッケージたちは破壊的な変更を余儀なくされたらしい。で、babel 6系のpeerDependencyであるbabel-coreを使うライブラリの移行を楽にすべくこのパッケージが存在する、ということらしいですね。

解決にあたって

ここここを参照しました。

以下はvue-test-utilsにコントリビュートされているらしいeddyerburghさんのコメントです。

eddyerburgh commented on 17 Feb •
We have babel-core as a peerDependency, it's up to you to use either @bridge or 6 (for vue-jest <4).

ふむふむ、vue-jestが4系に上がるまではbabelの6系を使うか、@bridgeパッケージを使えってことですね。
ちなみに2019年10月の段階ではvue-jestはまだ3系が最新みたいですね。

vue-jestのgithubのreadmeには

以下のように書かれていました。

Usage with Babel 7
If you use jest > 24.0.0 and babel-jest make sure to install babel-core@bridge

npm install --save-dev babel-core@bridge

jestのバージョンも関係してるみたいですね。
jest24.0.0より上のバージョンで、babel-jestを使っている場合はbabel-core@bridgeをおとなしく入れましょう。

51
24
1

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
51
24