Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CLI throws TypeError when used with --safelist and doesn't purge #513

Closed
dwbruhn opened this issue Nov 6, 2020 · 0 comments
Closed

CLI throws TypeError when used with --safelist and doesn't purge #513

dwbruhn opened this issue Nov 6, 2020 · 0 comments
Labels

Comments

@dwbruhn
Copy link

dwbruhn commented Nov 6, 2020

This is pretty simple to reproduce with version 3.0.0.

Create a test.js file:

var a = "class1";

And a test.css file:

.class1 {
    color: blue;
}

.class2 {
    color:red;
}

.class3 {
    color: green;
}

Then run purgecss --content test.js --css test.css --safelist class2 (as documented):

$ npx purgecss --content test.js --css test.css --safelist class2                                                                                                                                      [14:28:56]
[{"css":".class1 {\n    color: blue;\n}\n\n.class2 {\n    color:red;\n}\n\n.class3 {\n    color: green;\n}\n","file":"test.css"}]
(node:15305) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
    at U.shouldKeepSelector (/Users/dbruhn/repos/temp/node_modules/purgecss/lib/purgecss.js:1:9032)

The output is created despite the error, but all classes are preserved. (class3 should have been purged.)

Purging works fine without the whitelist:

$ npx purgecss --content test.js --css test.css                                                                                                                                                        [14:28:59]
[{"css":".class1 {\n    color: blue;\n}\n","file":"test.css"}]

The code is throwing because this.options.safelist.greedy is undefined:

if (this.options.safelist.greedy.length > 0) {

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@dwbruhn @Ffloriel and others