CleanWebpackPlugin is not a constructor
Posted jieker
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CleanWebpackPlugin is not a constructor相关的知识,希望对你有一定的参考价值。
在学习webpack根据入门教程"清理/dist文件时"出错了,网上找了下改下写法就好了,在此记录下
首先安装 clean-webpack-plugin 插件
npm install clean-webpack-plugin --save-dev
确保安装成功
其次修改webpack.config.js配置文件
// webpack版本:4.35.0 // 教程原写法,报错 const CleanWebpackPlugin = require("clean-webpack-plugin"); plugins: [ new CleanWebpackPlugin([‘dist‘]) ]
// new的时候不传参,报错 const CleanWebpackPlugin = require("clean-webpack-plugin"); plugins: [ new CleanWebpackPlugin() ] // 另一种写法,也报错 const CleanWebpackPlugin = require("clean-webpack-plugin"); plugins: [ new CleanWebpackPlugin([‘dist‘], root: path.resolve(__dirname, ‘../‘), //根目录 ) ] // =============================分割线============================== // 修改下导入方式,new的时候不传参,正确 const CleanWebpackPlugin = require("clean-webpack-plugin"); plugins: [ new CleanWebpackPlugin() ]
以上是关于CleanWebpackPlugin is not a constructor的主要内容,如果未能解决你的问题,请参考以下文章
TypeError: CleanWebpackPlugin is not a constructor
CleanWebpackPlugin is not a constructor
webpack报错:' CleanWebpackPlugin is not a constructor'
使用clean-webpack-plugin小插件报错CleanWebpackPlugin is not a constructor