Skip to content
This repository was archived by the owner on Dec 28, 2021. It is now read-only.
This repository was archived by the owner on Dec 28, 2021. It is now read-only.

v8.0.0 doesn’t work with CJS #78

Closed
@valtlai

Description

@valtlai

The version 8.0.0 doesn’t work when using CJS. That’s because there’s no a default export (module.exports) but an export called default (i.e. module.exports.default). This means the plugin can’t be used with postcss-load-config configured with package.json, for example.

Here’s a test code:

const postcss = require('postcss');
const nesting = require('postcss-nesting');

const css = `
a, b {
  color: red;

  & c, & d {
    color: white;
  }
}
`;

postcss([nesting]).process(css, { from: undefined })
  .then((result) => console.log(result.css));

And here’s the result when running it from a CLI:

$ node .
/Users/x/postcss-nesting-test/node_modules/postcss/lib/processor.js:60
        throw new Error(i + ' is not a PostCSS plugin')
        ^

Error: [object Object] is not a PostCSS plugin
    at Processor.normalize (/Users/x/postcss-nesting-test/node_modules/postcss/lib/processor.js:60:15)
    at new Processor (/Users/x/postcss-nesting-test/node_modules/postcss/lib/processor.js:9:25)
    at postcss (/Users/x/postcss-nesting-test/node_modules/postcss/lib/postcss.js:25:10)
    at Object.<anonymous> (/Users/x/postcss-nesting-test/index.js:14:1)
    at Module._compile (node:internal/modules/cjs/loader:1108:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Function.Module._load (node:internal/modules/cjs/loader:828:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47

If I import the default property:

- const nesting = require('postcss-nesting');
+ const nesting = require('postcss-nesting').default;

it works as expected:

$ node .

a, b {
  color: red
}
a c, a d, b c, b d {
    color: white;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions