TypeError: CleanWebpackPlugin is not a constructor

Posted steamed-twisted-roll

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TypeError: CleanWebpackPlugin is not a constructor相关的知识,希望对你有一定的参考价值。

在项目中引入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‘
    )
],   

 

 

以上是关于TypeError: CleanWebpackPlugin is not a constructor的主要内容,如果未能解决你的问题,请参考以下文章