【webpack4x】TypeError: CleanWebpackPlugin is not a constructor

// 对于最新的webpack版本:4.35.2
 
// 在原教程中,抛错原写法
const CleanWebpackPlugin = require("clean-webpack-plugin");
 
...
 
plugins: [
    new CleanWebpackPlugin(['dist'])
]
 
...
 
// 另一种错误写法
 
const CleanWebpackPlugin = require("clean-webpack-plugin");
 
...
 
plugins: [
    new CleanWebpackPlugin(['dist'], {
        root: path.resolve(__dirname, '../'),   //根目录
    })
]
 
...
 
// =============================分割线==============================
 
// 正确写法
 
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
 
...
 
plugins: [
    new CleanWebpackPlugin()
]
 
...

转载于:https://www.cnblogs.com/fe-linjin/p/11325895.html

你可能感兴趣的:(【webpack4x】TypeError: CleanWebpackPlugin is not a constructor)