So I am sort of new to webpack since I never created my own workflow and I am trying to set up an enviorement to compile ES2015+ JS and SCSS code now for the first time. For some reason when I try to compile my webpack I get the error Module build failed: Error: Cannot find module '@babel/core'
. Yet I have installed it with npm install
Webpack.config.js
module.exports = {
entry: './components/js/app.js',
output: {
filename: './dist/main.js'
},
module: {
loaders: [
{test: /\.js$/, loader: "babel-loader", exclude: /node_modules/},
{test: /\.scss$/, loader: "style-loader!css-loader!sass-loader"}
],
}
}
.babelrc
{
"presets": [
"@babel/preset-env"
]
}
Package.json
{
"name": "webpack-env",
"version": "1.0.0",
"description": "Webpack",
"main": "components/js/app.js",
"scripts": {
"build": "webpack"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/preset-env": "^7.0.0-beta.39",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"css-loader": "^0.28.5",
"node-sass": "^4.5.3",
"sass-loader": "^6.0.6",
"style-loader": "^0.18.2",
"webpack": "^3.4.1"
},
"dependencies": {}
}
Is there something I am missing?
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.
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.
Alright after some digging I've found the problem. The problem is that I've installed a newer version of babel, @babel/preset-env
which is babel version 7. Version 6 isn't working that way (as I believe, not sure) and for version 6 you have to run npm install --save-dev babel-preset-env
instead of npm install --save-dev @babel/preset-env
as I did.
The .babelrc file becomes
{
"presets": ["env"]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With