I keep getting the error Module not found: Error: Cannot resolve 'babel_loader'
Why? babel-loader is installed in node/modules, @babel-core
too, both are also present in package.json
. I've tried to reinstall babel-loader, changed webpack.config several times, and restarted both IDE and terminal, and it still doesn't work.
My webpack.config.js
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: "./src/index.js",
output: {
filename: "main.js",
path: path.resolve(__dirname, "build"),
},
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, "public", "index.html"),
}),
],
devServer: {
static: {
directory: path.join(__dirname, 'build'),
},
port: 3000,
},
module: {
rules: [
{
test: /\.(js)$/,
exclude: /(node_modules)/,
use: {
loader: 'babel_loader'
},
},
]
},
resolve: {
modules: ['node-modules'],
extensions: ['*', '.js'],
}
};
My package.json
:
{
"name": "mybuh",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack --mode production",
"start": "webpack serve --mode development",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-loader": "^9.1.2",
"@babel/core": "^7.21.8",
"@babel/preset-env": "^7.21.5",
"webpack": "^5.83.1",
"webpack-cli": "^5.1.1",
"html-webpack-plugin": "^5.5.1",
"webpack-dev-server": "^4.15.0"
}
}
My problem was, i made a typo, i wrote
{
"loader": "babel_loader"
}
instead of:
{
"loader": "babel-loader"
}