2

I am getting following error. Can't figure out solution. I found many post which looks duplicate here but, nothing work.

like: Requires Babel "7.0.0-0" but was loaded with "6.26.3"

node_modules@babel\helper-plugin-utils\lib\index.js

throw Object.assign(err, {

Error: 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.

Here following is my package.json

"dependencies": {
    "express": "^4.16.4",
    "isomorphic-fetch": "^2.2.1",
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-redux": "^5.1.1",
    "react-router": "^4.3.1",
    "react-router-config": "^1.0.0-beta.4",
    "react-router-dom": "^4.3.1",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0"
  },
  "devDependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.2.2",
    "@babel/plugin-proposal-class-properties": "^7.2.0",
    "@babel/plugin-transform-runtime": "^7.2.0",
    "@babel/preset-env": "^7.3.1",
    "@babel/preset-react": "^7.0.0",
    "babel-core": "^7.0.0-bridge.0",
    "babel-jest": "^24.0.0",
    "babel-loader": "^7.1.5",
    "css-loader": "^1.0.1",
    "cypress": "^3.1.3",
    "enzyme": "^3.8.0",
    "enzyme-adapter-react-16": "^1.7.1",
    "enzyme-to-json": "^3.3.5",
    "extract-text-webpack-plugin": "^4.0.0-beta.0",
    "html-webpack-plugin": "^3.2.0",
    "jest": "^24.0.0",
    "jest-fetch-mock": "^2.0.1",
    "json-loader": "^0.5.7",
    "nodemon": "^1.18.9",
    "npm-run-all": "^4.1.5",
    "open": "0.0.5",
    "redux-devtools": "^3.4.2",
    "redux-mock-store": "^1.5.3",
    "regenerator-runtime": "^0.13.1",
    "style-loader": "^0.23.1",
    "uglifyjs-webpack-plugin": "^2.0.1",
    "webpack": "^4.26.1",
    "webpack-cli": "^3.1.2",
    "webpack-dev-server": "^3.1.14",
    "webpack-node-externals": "^1.7.2"
  },
  "babel": {
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ],
    "plugins": [
      "@babel/plugin-transform-runtime",
      "@babel/plugin-proposal-class-properties"
    ]
  }

I am getting on npm start.

"start": "webpack -d && nodemon --exec babel-node ./server"
Community
  • 1
  • 1
ketan
  • 19,129
  • 42
  • 60
  • 98
  • How did you get that error? On `npm install` on `npm update`...? Are you using `npm`? are you using `yarn`? do you have a lock file? In other words: could you please describe your build process? Thanks! – Josep Jan 28 '19 at 11:13
  • @Josep Edited question. Yes Of course i have `package-lock.json` file – ketan Jan 28 '19 at 11:15
  • Please try this: first make sure that you have committed your latest changes on git, just in case, then go ahead and do this: `rm -rf node_modules && rm package-lock.json && npm install`... Do you get any warnings in the console? could you please share them? It's also possible that things start working after performing those steps :-) – Josep Jan 28 '19 at 11:18
  • @Josep Ok. let me try and know you – ketan Jan 28 '19 at 11:20
  • @Josep done command without any error. Still getting same error while npm start – ketan Jan 28 '19 at 11:30
  • In my case sometimes babel version over 7 didn't work. Try to install npm i @babel@6, try lower version, or npm i @babel/core@6 – Freestyle09 Jan 28 '19 at 11:30
  • @Freestyle09 but, i want to use https://github.com/jamiebuilds/react-loadable for that i think babel 7 requird – ketan Jan 28 '19 at 11:31
  • Have you tried ?? Maybe 6 version will work, Once I had similar problem and reinstalling babel to lower version solved my problem :P Make some copy and try maybe It will work, I don't have any other ideas to solve your problem – Freestyle09 Jan 28 '19 at 11:36
  • 1
    @Freestyle09 yeah. i was working with 6 already but, after using react-loadable it asked me to use version 7 – ketan Jan 28 '19 at 11:41

2 Answers2

5

Found it :-)

I noticed that babel-node is not among your dependencies, therefore you must be using a global version of babel-node, likely version 6... So, just add the correct one into your devDependencies:

npm install --save-dev @babel/node 
Josep
  • 12,926
  • 2
  • 42
  • 45
0

What is the output of npm ls babel-core? I realised that I have babel-cli@6.26.0 and babel-register@6.26.0, I removed them and installed @babel/cli and @babel/register

terminal output

My config files look like this: In package.json:

  "resolutions": {
      "babel-core": "7.0.0-bridge.0"
  }

In .babelrc :

{
"presets": [
  "@babel/preset-env",
  "@babel/preset-react"
],
"plugins": [
  "@babel/plugin-transform-runtime",
  "@babel/plugin-proposal-class-properties",
  "@babel/plugin-proposal-object-rest-spread",
  "@babel/plugin-transform-async-to-generator"
]}

After all changes, it might be a good idea to delete your lock file and rebuild it.

Mahdiyeh
  • 865
  • 11
  • 12