Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module 'babel-core' but @babel/core is installed

After running jest tests, one of them is getting this error.

Cannot find module 'babel-core'

      at Object.<anonymous> (node_modules/vue-jest/lib/compilers/babel-compiler.js:1:15)

It's pretty straightforward. babel-core is not installed. But a newer version of babel-core (@babel/core) is installed!

Here I add my package.json devDependencies

"devDependencies": {
    "@babel/core": "^7.4.5",
    "@babel/preset-env": "^7.4.5",
    "@babel/runtime": "^7.4.4",
    "@vue/cli-plugin-babel": "^3.7.0",
    "@vue/cli-plugin-eslint": "^3.7.0",
    "@vue/cli-plugin-pwa": "^3.7.0",
    "@vue/cli-service": "^3.7.0",
    "@vue/test-utils": "^1.0.0-beta.29",
    "axios-mock-adapter": "^1.16.0",
    "babel-eslint": "^10.0.1",
    "babel-loader": "^8.0.6",
    "babel-preset-env": "^1.7.0",
    "bootstrap": "^4.3.1",
    "eslint": "^5.8.0",
    "eslint-plugin-vue": "^5.0.0",
    "gulp-babel": "^8.0.0",
    "jest": "^24.8.0",
    "jest-serializer-vue": "^2.0.2",
    "jest-transform-stub": "^2.0.0",
    "jest-watch-typeahead": "^0.3.1",
    "json-loader": "^0.5.7",
    "less-loader": "^4.1.0",
    "postcss-flexbugs-fixes": "^4.1.0",
    "postcss-loader": "^3.0.0",
    "raw-loader": "^2.0.0",
    "sw-precache-webpack-plugin": "^0.11.5",
    "vue-jest": "^3.0.4",
    "vue-loader": "^15.7.0",
    "vue-template-compiler": "^2.5.21",
    "webpack": "^4.32.0",
    "webpack-cli": "^3.3.2"
  },

I want to know how can I get my babel loader or jest to recognize @babel/core and not babel-core. I read that babel-loader 8+ should do the work, but its not working as expected.

Didn't know it was a vue-jest problem, but thanks.

like image 993
Jalil Avatar asked May 24 '19 09:05

Jalil


People also ask

Can not find Babel core?

To solve the error "Cannot find module '@babel/core'", make sure to install the @babe/core package by opening your terminal in your project's root directory and running the following command: npm i -D @babel/core and restart your IDE and development server.

What is Babel core used for?

Babel is a JavaScript compiler Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.


1 Answers

babel-core is not @babel/core – they are different packages.

You should be able to get away here with

  • installing the babel-core bridge,
  • or switch to a newer, unreleased version of vue-jest which uses @babel/core.
like image 182
AKX Avatar answered Oct 05 '22 14:10

AKX