【问题标题】:Why do i get this error in Webpack 5.11.0: 1 ERROR in child compilations?为什么我在 Webpack 5.11.0 中收到此错误:子编译中出现 1 错误?
【发布时间】:2020-12-22 22:24:58
【问题描述】:

所以我在尝试编译时在我的 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"
  }
}

有人可以帮助我吗?如果有人需要任何类型的信息,我会保持警惕。

【问题讨论】:

    标签: webpack html-webpack-plugin webpack-file-loader webpack-html-loader


    【解决方案1】:

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

    【讨论】:

    • 是的,这就是问题所在,谢谢!谁发现了这个问题,请检查两次来自 HTML 和 JS 的所有路径。
    • 拯救了我的一天。我从过去 4 小时开始一直在寻找这个解决方案。这是一个愚蠢的错误。我们不能直接忽略html-loader中的坏链接吗?
    猜你喜欢
    • 2012-03-13
    • 1970-01-01
    • 1970-01-01
    • 2013-08-14
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 2018-10-08
    相关资源
    最近更新 更多