为什么我在 Webpack 5.11.0: 1 ERROR in child compilers 中得到这个错误?

问题描述

所以我在尝试编译时在我的 webpack 代码中收到此错误,当我以生产模式启动时会发生这种情况,当我删除 html-loader 时,错误消失了,我还包括 HtmlWebpackPlugin 和 file-loader 以供使用:

webpack.prod.js:

const path = require("path");
const common = require('./webpack.common.js');
const { merge } = require('webpack-merge');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = merge(common,{
  mode: "production",output: {
    publicPath: '',filename: "js/[name].[contenthash].bundle.js",path: path.resolve(__dirname,"dist")
  },plugins: [
    new CleanWebpackPlugin()
  ]
});

webpack.common.js:

const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  entry: {
    main: "./src/index.js"
  },plugins: [
    new HtmlWebpackPlugin({
      template: './src/html/index.html'
    })
  ],module: {
    rules: [
      {
        test: /\.scss$/,use: [
          'style-loader','css-loader','sass-loader'
        ]
      },{
        test: /\.html$/,use: [
          'html-loader'
        ]
      },{
        test: /\.(svg|png|jpg|gif)$/,use: {
          loader: 'file-loader',options: {
            name: '[name].[hash].[ext]',outputPath: 'imgs'
          }
        }
      }
    ]
  }
};

package.json:

  "devDependencies": {
    "clean-webpack-plugin": "^3.0.0","css-loader": "^5.0.1","file-loader": "^6.2.0","html-loader": "^1.3.2","html-webpack-plugin": "^4.5.0","node-sass": "^5.0.0","sass-loader": "^10.1.0","style-loader": "^2.0.0","webpack": "^5.11.0","webpack-cli": "^4.2.0","webpack-dev-server": "^3.11.0","webpack-merge": "^5.7.3"
  }
}

有人可以帮助我吗?如果有人需要任何类型的信息,我会随时了解。

解决方法

我建议您检查 html 文件的路径。如果路径错误,通常会发生这种情况

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...