TypeError: CleanwebpackPlugin is not a constructor TypeError: CleanwebpackPlugin is not a constructor vue.js vue.js

TypeError: CleanwebpackPlugin is not a constructor


The correct one is to use this import:

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

And then instead of passing an array with the distribution folder, change it to

plugins: [     new CleanWebpackPlugin(),     //...]


I had the same problem, and I solved it in the following way:

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


I had the same issue today, right now. As you can tell, there was a mismatch between the docs and the actual code. And in fact, you can see in the last commit they merged both to the documentation:

enter image description here

and also to the code:

enter image description here

So I just switched from const CleanWebpackPlugin = require('clean-webpack-plugin') to

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

and it works fine.

I think you may have been caught in between things. Reinstall the npm package and try again, it should work.

I wrote a bit of what you can see in their public repository because very often when sudden changes like this happen, you'll find your own answer in the repo, probably in the last commits. And it's good reading a bit of the code you use, especially if it helps you troubleshoot your issue :)