英文:
error Module not found: Error: Can't resolve 'babel_loader'
问题
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"
}
}
英文:
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"
}
}
答案1
得分: 0
我的问题是,我犯了一个拼写错误,我写成了
{
"loader": "babel_loader"
}
而不是:
{
"loader": "babel-loader"
}
英文:
My problem was, i made a typo, i wrote
{
"loader": "babel_loader"
}
instead of:
{
"loader": "babel-loader"
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论