Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HtmlWebpackInlineSourcePlugin TypeError: Cannot read property 'getHooks' of undefined

I'm getting the error in the title when trying to build the following webpack file:

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'
};

Any idea why?

FWIW I'm using yarn workspaces.

like image 660
Sammy Avatar asked Oct 15 '22 05:10

Sammy


1 Answers

HtmlWebpackInlineSourcePlugin is invoking getHooks method of HtmlWebpackPlugin during compilation

This method is only available in version 4 and up of HtmlWebpackPlugin.

This is why the documentation recommends to use this version and up.

You can get this version by installing html-webpack-plugin@next

like image 113
Oluwafemi Sule Avatar answered Oct 21 '22 05:10

Oluwafemi Sule