Search code examples
reactjsbabeljswebpack-4babel-loader

How to upgrade to Babel 7


I tried to upgrade Webpack and Babel to 4, 7 respectively but couldn’t make it work. Also the official doc isn’t helping much with the upgrade.

I am getting following issue

compiler error: ERROR in Cannot find module '@babel/core' @ multi main

dependencies I am using:

"babel-core": "^6.26.3",
"babel-eslint": "^9.0.0",
"babel-loader": "^8.0.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"webpack": "^4.15.0",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4"

What can I try next?


Solution

  • Babel changed the name of the module babel-core to @babel/core. Just run npm install @babel/core. This will install the latest version of Babel core.

    Most of the packages in Babel has been renamed to follow the pattern @babel/PACKAGE_NAME. So if you want to upgrade, change the package names to follow the pattern and run npm install.

    To upgrade to Babel 7 you can use this migration guide.