Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Using .postcssrc.ts results into transpilation error #14758

Closed
7 tasks done
ElPrudi opened this issue Oct 25, 2023 · 2 comments
Closed
7 tasks done

Using .postcssrc.ts results into transpilation error #14758

ElPrudi opened this issue Oct 25, 2023 · 2 comments

Comments

@ElPrudi
Copy link

ElPrudi commented Oct 25, 2023

Describe the bug

Using the typescript format for a postcss config, ts-node does not respect the tsconfig.json target and transpiles the import syntax to require() resulting into an error with "type": "module" in package.json.

Workaround: change it from .postcssrc.ts to .postcssrc.js

Reproduction

https://stackblitz.com/edit/vitejs-vite-l8rdtt

Steps to reproduce

Just use this config in a file called .postcssrc.ts:

import type { Config } from 'postcss-load-config'
import cssnano from 'cssnano'

export default ({ env }): Config => ({
    plugins: [
        cssnano({
            preset: 'default'
        })
    ]
})

System Info

vite version 4.5.0
node: 18.17.1

Used Package Manager

npm

Logs

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: ...\.postcssrc.ts
require() of ES modules is not supported.
require() of ...\.postcssrc.ts from ...\node_modules\vite\dist\node\chunks\dep-bb8a8339.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.

Validations

@stackblitz
Copy link

stackblitz bot commented Oct 25, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@bluwy
Copy link
Member

bluwy commented Oct 26, 2023

It's a bug in postcss-load-config: postcss/postcss-load-config#239. In Vite 5, we have also provided a workaround to support .postcssrc.cts: https://main.vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated

Closing this for now. I'd suggest following the linked postcss-load-config PR.

@bluwy bluwy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants