webpack TypeError: CleanWebpackPlugin is not a constructor

TypeError: CleanWebpackPlugin is not a constructor:https://www.cnblogs.com/steamed-twisted-roll/p/10990309.html

cleanWebpackplugin 升级踩坑:http://www.imooc.com/article/289614

 https://www.jianshu.com/p/0e99366ce796

在项目中引入clean-webpack-plugin打包后报错

new CleanWebpackPlugin(),
^

TypeError: CleanWebpackPlugin is not a constructor

项目写法:
引入: cnpm i  clean-webpack-plugin -D
webpack.config.js中
复制代码
const CleanWebpackPlugin = require('clean-webpack-plugin')

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

看了一下githup上的写法,现在新版本的clean-webpack-plugin引入已经改为const CleanWebpackPlugin require('clean-webpack-plugin');

所以修改引入写法就OK了

复制代码
const {CleanWebpackPlugin} = require('clean-webpack-plugin')

plugins: [
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
        filename: 'index.html',
        template: './src/index.html'
    })
],   
复制代码
原文地址:https://www.cnblogs.com/bydzhangxiaowei/p/12381398.html