question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

  • I agree to follow this project’s Code of Conduct

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:17
  • Comments:12

github_iconTop GitHub Comments

8reactions
paper-florentcommented, Oct 11, 2022

it looks like it should be

const { PurgeCSSPlugin } 			= require("purgecss-webpack-plugin");
0reactions
paper-florentcommented, Nov 2, 2022

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 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack 5 - PurgeCss - Not a Constructor Error
So apparently this is a webpack-purgecss-plugin 5.0 issue since webpack 5.0 So I downgraded the plugin to 4.1.3 and it works again.
Read more >
'Purgecss is not a constructor' when following the JS API ...
Hi, I'm trying to follow the ES5 JS API examples but it looks like something is going wrong with the export as I'm...
Read more >
PurgeCSSPlugin.(constructor)
PurgeCSSPlugin.(constructor). Constructs a new instance of the PurgeCSSPlugin class. Signature: constructor(options: UserDefinedOptions); ...
Read more >
purgecss-webpack-plugin - npm
PurgeCSS plugin for webpack - Remove unused css. Latest version: 5.0.0, last published: 3 months ago. Start using purgecss-webpack-plugin in ...
Read more >
Removing unused CSS with Purgecss/UnCSS - sage
// resources/assets/build/webpack.config.optimize.js // ... const glob = require('glob-all'); const PurgecssPlugin = require('purgecss-webpack-plugin'); module ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found