CleanWebpackPlugin is not a constructor webpack报错

报错信息:CleanWebpackPlugin is not a constructor

> [email protected] build /Users/zl/Desktop/rs/webpack/webpack-demo
> webpack

/node_modules/webpack-cli/bin/cli.js:93
                throw err;
                ^

TypeError: CleanWebpackPlugin is not a constructor
    at Object. (/Users/zl/Desktop/rs/webpack/webpack-demo/webpack.config.js:20:3)
    at Module._compile (/Users/zl/Desktop/rs/webpack/webpack-demo/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (/Users/zl/Desktop/rs/webpack/webpack-demo/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
    at WEBPACK_OPTIONS (/Users/zl/Desktop/rs/webpack/webpack-demo/node_modules/webpack-cli/bin/utils/convert-argv.js:114:13)
    at requireConfig (/Users/zl/Desktop/rs/webpack/webpack-demo/node_modules/webpack-cli/bin/utils/convert-argv.js:116:6)
    at /Users/zl/Desktop/rs/webpack/webpack-demo/node_modules/webpack-cli/bin/utils/convert-argv.js:123:17
    at Array.forEach ()
    at module.exports (/Users/zl/Desktop/rs/webpack/webpack-demo/node_modules/webpack-cli/bin/utils/convert-argv.js:121:15)
    at yargs.parse (/Users/zl/Desktop/rs/webpack/webpack-demo/node_modules/webpack-cli/bin/cli.js:71:45)
    at Object.parse (/Users/zl/Desktop/rs/webpack/webpack-demo/node_modules/yargs/yargs.js:567:18)
    at /Users/zl/Desktop/rs/webpack/webpack-demo/node_modules/webpack-cli/bin/cli.js:49:8
    at Object. (/Users/zl/Desktop/rs/webpack/webpack-demo/node_modules/webpack-cli/bin/cli.js:366:3)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object. (/Users/zl/Desktop/rs/webpack/webpack-demo/node_modules/webpack/bin/webpack.js:156:2)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `webpack`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/zl/.npm/_logs/2019-11-13T01_52_16_002Z-debug.log
image.png

错误写法:

const CleanWebpackPlugin = require('clean-webpack-plugin');

正确写法:

const { CleanWebpackPlugin } = require('clean-webpack-plugin');
plugins: [
        new CleanWebpackPlugin(),
    ],

你可能感兴趣的:(CleanWebpackPlugin is not a constructor webpack报错)