postcss / postcss-load-config

Autoload Config for PostCSS
MIT License
638 stars 71 forks source link

Error loading postcss.config.ts with "type": "module" in package.json and "module": "ESNext" in tsconfig.json #244

Closed kuchta closed 1 year ago

kuchta commented 1 year ago

When building a project by vite using basic react configuration postcss fails with:

Error (Logs|Stacks)

[Failed to load PostCSS config: Failed to load PostCSS config: [Error] Must use import to load ES Module: ./postcss.config.ts
require() of ES modules is not supported.
require() of ./postcss.config.ts from ./node_modules/vite/dist/node/chunks/dep-f7d05e3f.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
Instead change the requiring code to use import(), or remove "type": "module" from ./package.json.

When I remove "type": "module" from package.json I get:

[Failed to load PostCSS config: Failed to load PostCSS config (searchPath: /Users/kuchta/Projects/radixverse): [SyntaxError] Unexpected token 'export'
/Users/kuchta/Projects/radixverse/postcss.config.ts:1
export default {
^^^^^^

SyntaxError: Unexpected token 'export'

Environment

OS node npm postcss vite
macOS - 13.3.1 18.16.0 9.5.1 8.4.23 4.3.4
ai commented 1 year ago

Dublicate https://github.com/postcss/postcss-load-config/issues/239