purgecss icon indicating copy to clipboard operation
purgecss copied to clipboard

[Bug]: Webpack: TypeError: PurgeCSSPlugin is not a constructor

Open gndk opened this issue 2 years ago • 5 comments

Describe the bug

After upgrading to 5.0.0, my webpack build failed with TypeError: PurgeCSSPlugin is not a constructor.

To Reproduce

Use webpack plugin with current instructions:

const PurgeCSSPlugin = require('purgecss-webpack-plugin')

then somewhere new PurgeCSSPlugin(...)

Expected Behavior

Webpack build succeeds.

Environment

v. 5.0.0

Add any other context about the problem here

I fixed my problem by simply changing

const PurgeCSSPlugin = require('purgecss-webpack-plugin');

to

const { PurgeCSSPlugin } = require('purgecss-webpack-plugin');

I don't know if this change was intended with the 5.0.0 update. If yes, it would be a quick fix in the webpack plugin instructions :)

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

gndk avatar Sep 13 '22 21:09 gndk

+1

CutImger avatar Sep 20 '22 16:09 CutImger

Adding PurgeCSSPlugin between curly brackets doesn't fix the problem, I still get that error. Webpack version: "webpack": "^5.74.0", "webpack-cli": "^4.10.0",

razvanFrandes avatar Sep 28 '22 09:09 razvanFrandes

+1

JayDarji avatar Sep 28 '22 10:09 JayDarji

adding curly brackets solved the problem for us as show in the new 'usage'. Maybe this should have been report as a breaking change?

jgroc-de avatar Sep 28 '22 14:09 jgroc-de

In the changelog, it says it supports default and named export, and there is a commit for that.

But in the next commit, it removes the default export.

I think the changelog should up updated instead to say only named export can be used.

zhang-li-80 avatar Sep 30 '22 12:09 zhang-li-80

same

thomas-void0 avatar Oct 09 '22 08:10 thomas-void0

Adding PurgeCSSPlugin between curly brackets doesn't fix the problem, I still get that error. Webpack version: "webpack": "^5.74.0", "webpack-cli": "^4.10.0",

denOldTimer avatar Oct 10 '22 11:10 denOldTimer

Same...

paper-florent avatar Oct 11 '22 18:10 paper-florent

it looks like it should be

const { PurgeCSSPlugin } 			= require("purgecss-webpack-plugin");

paper-florent avatar Oct 11 '22 18:10 paper-florent

I temporarily solved my issue by downgrading back to version 4.1.3 but I missing out on the new stuff. Also got a new issue, it's definitely a webpack issue, not sure if it's a webpack-purgecss-plugin issue. Namely: javascript - toggle not functioning after webpack compilation. In the browser inspector I can see the toggle working but the class being added doesn't override the current class. At first, I thought purgecss was removing the class properties because it hasn't been used initially. And that still may be true, hence my mention of if. It is as if the specificity of the toggle class {.active} is lower than the current class and thus is voided.

That's why I think this is a purgecss issue

denOldTimer avatar Oct 14 '22 11:10 denOldTimer

FYI for anyone having problems with this please note that the casing has to match exactly. You need to change the import to:

const { PurgeCSSPlugin } = require('purgecss-webpack-plugin');

and the call after this to

new PurgeCSSPlugin({ ...

Note the capitalisation of CSS.

Dave3of5 avatar Nov 02 '22 09:11 Dave3of5

FYI for anyone having problems with this please note that the casing has to match exactly. You need to change the import to:

const { PurgeCSSPlugin } = require('purgecss-webpack-plugin');

and the call after this to

new PurgeCSSPlugin({ ...

Note the capitalisation of CSS.

Check my comment just before @Dave3of5 :)

paper-florent avatar Nov 02 '22 10:11 paper-florent

Documentation updated and is showing the correct syntax now

const { PurgecssPlugin } = require("purgecss-webpack-plugin");

Ffloriel avatar Feb 17 '23 19:02 Ffloriel

const purgeCssWebpackPlugin = require("purgecss-webpack-plugin").PurgeCSSPlugin;

This working for me.

PiyushAgrawal1243 avatar Jun 16 '23 03:06 PiyushAgrawal1243