错误:module.exports = __webpack_require__.p .... 模块未定义

时间:2021-02-06 10:18:55

标签: webpack webpack-5

当我将 webpack 从 4 更新到 5 时,错误存在。

ERROR in   Error: F:\cloud-music\public\index.html:13
  module.exports = __webpack_require__.p + "static/media/javascript,__webpack_public_path__ = htmlWebpackPluginPublicPath;.93bce551.bin";
  ^
  ReferenceError: module is not defined

然而,当我查看 index.html 时,没有任何 module index.html

请错误信息more detail

这里是我如何定义 htmlWebpackPlugin

           new HtmlWebpackPlugin(
                Object.assign({}, {
                        inject: true,
                        template: paths.appHtml,
                    },
                    isEnvProduction ? {
                        minify: {
                            removeComments: true,
                            collapseWhitespace: true,
                            removeRedundantAttributes: true,
                            useShortDoctype: true,
                            removeEmptyAttributes: true,
                            removeStyleLinkTypeAttributes: true,
                            keepClosingSlash: true,
                            minifyJS: true,
                            minifyCSS: true,
                            minifyURLs: true,
                        },
                    } :
                    undefined
                )

谢谢!德米特里·涅斯捷连科 请检查我的代码,我是 webpack 新手

{
      loader: require.resolve('file-loader'),
      exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.json$/], 
      // was ---- exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
      options: {
            name: 'static/media/[name].[hash:8].[ext]',
      },
},

我像上面一样更改了代码,但是,我没有工作。 当我删除所有这些时,它起作用了!不知道为什么???

1 个答案:

答案 0 :(得分:0)

这是一个插件的错误。此问题中描述的修复:

https://github.com/jantimon/html-webpack-plugin/issues/1589