TypeError: CleanWebpackPlugin is not a constructor

Front end developers must read! Starting from scratch, teach you to build a low code website platform in stages>>>

Introduce clean webpack plugin into the project and report an error after packaging

new CleanWebpackPlugin(),
^

TypeError: CleanWebpackPlugin is not a constructor

Project writing method:

Introduction: cnpm Iclean webpack plugin – D

In webpack.config.js

const CleanWebpackPlugin = require('clean-webpack-plugin')

plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
        filename: 'index.html',
        template: './src/index.html'
    })
],        

After looking at the writing method on githup, the introduction of clean webpack plugin in the new version has been changed to const {clean webpack plugin} = require (‘clean webpack plugin ‘)

So it’s OK to modify and introduce the writing method

const {CleanWebpackPlugin} = require('clean-webpack-plugin')

plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
        filename: 'index.html',
        template: './src/index.html'
    })
],   

Similar Posts: