question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

vue-jest can't find babel

See original GitHub issue

While trying to test vue components I get the following error:

Cannot find module ‘babel-core’ at Object.<anonymous> (node_modules/vue-jest/lib/compilers/babel-compiler.js:1:15)

package.json:

"devDependencies": {
	"@babel/core": "^7.2.2",
	"@babel/plugin-syntax-dynamic-import": "^7.2.0",
	"@babel/preset-env": "^7.3.1",
	"@vue/test-utils": "^1.0.0-beta.29",
	"babel-jest": "^24.1.0",
	"babel-loader": "^8.0.5",
	"css-loader": "^2.1.0",
	"file-loader": "^3.0.1",
	"jest": "^24.1.0",
	"mini-css-extract-plugin": "^0.5.0",
	"node-sass": "^4.11.0",
	"sass-loader": "^7.1.0",
	"style-loader": "^0.23.1",
	"vue": "^2.6.6",
	"vue-jest": "^3.0.3",
	"vue-loader": "^15.6.2",
	"vue-router": "^3.0.2",
	"vue-template-compiler": "^2.6.6",
	"webpack": "^4.29.3",
},

.babelrc

{
	"presets": [
		"@babel/preset-env"
	],
	"plugins": [
		"@babel/plugin-syntax-dynamic-import"
	]
}

jest.config.js

module.exports = {
	verbose: true,
	moduleFileExtensions: [ "js", "json", "jsx", "ts", "tsx", "node", "vue" ],
	transform: {
		// process js with `babel-jest`
		"^.+\\.js$": "babel-jest",
		// process `*.vue` files with `vue-jest`
		".*\\.(vue)$": "vue-jest",
	}
};

When looking at the referenced file I can see:

const babel = require('babel-core')

Shouldn’t that be @babel/core?

Repository: https://github.com/SuperDJ/vue-jest-babel-core

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:13
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

85reactions
igraviouscommented, Apr 8, 2019

@eddyerburgh

We have babel-core as a peerDependency, it’s up to you to use either @bridge or 6 (for vue-jest <4).

How are we meant to know this?

9reactions
brightknight08commented, Mar 18, 2020

Is there any way on how to direct vue-jest to use babel.config.json instead of .babelrc? I recently ran into an error where jest fails :

SyntaxError: E:\l****\*****\src\components\NavBar.vue: 'import' and 'export' may only appear at the top level (233:0)

I found this too:

[vue-jest]: no .babelrc found, skipping babel compilation

But I have a fully working babel.config.json (as recommended by babel’s website)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Vue-jest can't find babel - Stack Overflow
Cannot find module 'babel-core' at Object. (node_modules/vue-jest/lib/compilers/babel-compiler.js:1:15). package.json:
Read more >
babel-jest - npm
Jest plugin to use babel for transformation.. Latest version: 29.3.1, ... Start using babel-jest in your project by running `npm i babel-jest`.
Read more >
Configuring Jest
Jest ships with two coverage providers: babel (default) and v8 . See the coverageProvider option for more details.
Read more >
cannot find module '@vue/compiler-dom' from 'node_modules ...
Cannot find module '@vue/compiler-dom' from 'node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js' Require stack: ... Favicon for stackoverflow.com ...
Read more >
Cannot find module 'babel-core' but @babel/core is installed ...
... for the question Cannot find module 'babel-core' but @babel/core is installed-Vue.js. ... unreleased version of vue-jest which uses @babel/core .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found