“error Module not found: Error: Can’t resolve ‘babel_loader'”

huangapple go评论52阅读模式
英文:

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"
}

huangapple
  • 本文由 发表于 2023年5月22日 14:22:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76303484.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定