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

 

 

相关文章:

  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-07-15
  • 2022-12-23
猜你喜欢
  • 2021-07-15
  • 2022-12-23
  • 2021-09-04
  • 2022-01-04
  • 2022-12-23
  • 2021-07-04
相关资源
相似解决方案