postcss / postcss-load-config

Autoload Config for PostCSS
MIT License
642 stars 72 forks source link

Support postcss.config.cjs #192

Closed ghost closed 3 years ago

ghost commented 4 years ago

When I add "type": "module" to package.json I get:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/me/src/postcss.config.js
require() of ES modules is not supported.
require() of /home/me/src/postcss.config.js from /home/me/src/node_modules/import-fresh/index.js is an ES module file as it is a .js file whose nearest
parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename postcss.config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/me/src/package.json.

If I follow the advice to change the extension to cjs I get:

You did not set any plugins, parser, or stringifier. Right now, PostCSS does nothing. Pick plugins for your case on https://www.postcss.parts/ and use them in postcss.config.js.

My postcss.config.{cjs,js} looks like:

module.exports = {
  plugins: [require("tailwindcss"), require("autoprefixer")]
};

Removing "type": "module" and using the js extension everything works.

original: https://github.com/postcss/postcss/issues/1329

ghost commented 4 years ago

Possibly related to https://github.com/davidtheclark/cosmiconfig/issues/224

andre-lergier commented 4 years ago

I have exactly the same issue.

mrzepinski commented 4 years ago

davidtheclark/cosmiconfig supports CJS imports from 7.0.0 so I've updated it here: https://github.com/michael-ciniawsky/postcss-load-config/pull/198

michael-ciniawsky commented 3 years ago

Related to #190

ai commented 3 years ago

Fixed in postcss-load-config 3.0