HtmlWebpackInlineSourcePlugin TypeError: Cannot read property 'getHooks' of undefined

HtmlWebpackInlineSourcePlugin TypeError: Cannot read property 'getHooks' of undefined

我在尝试构建以下 webpack 文件时遇到标题错误:

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');

module.exports = {
  module: {
    rules: [{
        test: /\.js$/,
        exclude: /(node_modules)/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      },
      {
        test: /\.(scss)$/,
        use: [{
          loader: 'style-loader', // inject CSS to page
        }, {
          loader: 'css-loader', // translates CSS into CommonJS modules
        }, {
          loader: 'postcss-loader', // Run post css actions
          options: {
            plugins: function() { // post css plugins, can be exported to postcss.config.js
              return [
                require('precss'),
                require('autoprefixer')
              ];
            }
          }
        }, {
          loader: 'sass-loader' // compiles Sass to CSS
        }]
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: 'src/index.html',
      inlineSource: '.(js|css)$'
    }),
    new HtmlWebpackInlineSourcePlugin()
  ],

  entry: './src/index.js',

  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },

  mode: 'development'
};

知道为什么吗?

FWIW 我正在使用 yarn 工作区。

HtmlWebpackInlineSourcePlugininvoking getHooks method of HtmlWebpackPlugin during compilation

此方法仅适用于版本4 and up of HtmlWebpackPlugin

这就是 the documentation recommends 使用此版本及更高版本的原因。

您可以通过安装html-webpack-plugin@next

获得此版本