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.

'Purgecss is not a constructor' when following the JS API examples

See original GitHub issue

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 getting a TypeError: Purgecss is not a constructor error. I think it’s probably something I’m doing wrong rather than a problem with the docs, but I’m not 100% sure.

This is my output from trying to run purgeCss.js with node v8.6.0.

/usr/local/bin/node /Users/name/Sites/project/core/www/sites/all/themes/custom/project_theme/purgeCss.js

/Users/name/SItes/project/aman/core/www/sites/all/themes/custom/project_theme/purgeCss.js:2
var purgecss = new Purgecss({
               ^

TypeError: Purgecss is not a constructor
    at Object.<anonymous> (/Users/name/Sites/project/core/www/sites/all/themes/custom/project_theme/purgeCss.js:2:16)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:607:3

Process finished with exit code 1

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Fflorielcommented, Feb 8, 2020

If you are using the latest version, the API changed a bit.

import PurgeCSS from 'purgecss'
const purgeCSSResults = await new Purgecss().purge({
  content: ['**/*.html'],
  css: ['**/*.css']
})

If you are using with require, you should be able to import it like this:

const { PurgeCSS } = require("purgecss");
3reactions
philwolstenholmecommented, Jan 18, 2018

Thanks for all your work on Purgecss @Ffloriel 😃 I’ve been using it for project at home for a while, and today I set it up on a project at work too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack 5 - PurgeCss - Not a Constructor Error
I keep getting the error PurgeCss is not a constructor when I run Webpack. Funny enough this used to work but ever since...
Read more >
Configuration - PurgeCSS
PurgeCSS is a tool to remove unused CSS from your project.
Read more >
purgecss - npm
Remove unused css selectors. Latest version: 5.0.0, last published: 3 months ago. Start using purgecss in your project by running `npm i ...
Read more >
Eliminating Unused CSS - SurviveJS
After this you'll end up with a tailwind.config.js file at the project root. ... At best, PurgeCSS can eliminate most, if not all,...
Read more >
TypeError: "X" is not a constructor in JavaScript | bobbyhadz
reject() with the new operator. typeerror is not a constructor. Here's an example of how the error occurs. index.js.
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