Skip to content

[Bug]: Configuration file is incorrectly imported from cli #1340

@giggio

Description

@giggio

Describe the bug

When using the cli and specifing the --config flag the file is incorrectly imported using await import, which creates an object with this structure:

{
  default: {}, // config
  'module.exports': {} // same config again
}

This is later merged with the other options, but the options never take effect.

This happens if you use the module.exports = {} syntax, which is explained in the docs.

This will work if you use an es module syntax, like so:

export const content = [];
export function defaultExtractor(content) { }
export const safelist = { };

But you will then get a warning from Node.js:

(node:2234469) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///.../purgecss.config.js is not specified and it doesn't parse as CommonJS.
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.

To Reproduce

  1. Create a config file as per docs.
  2. Create any css file named site.css.
  3. Edit node_modules/purgecss/bin/purgecss.js to log the output of the config:
            options.skippedContentGlobs = skippedContentGlobs;
        if (output)
            options.output = output;
    +   console.log('***', options);
        return options;
  4. Run: purgecss --config ./purgecss.config.js --css site.css --rejected

Expected Behavior

Configuration from cli args are merged into config from file and config file is not ignored.

Environment

Ubuntu 24, Node 23.10.0, Npm 10.9.2
@fullhuman/[email protected]
[email protected]

Add any other context about the problem here

This does not seem to be a docs only issue, as a warning is emitted by Node.js.

Code of Conduct

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions