Skip to content

Conversation

thecrypticace
Copy link
Contributor

@thecrypticace thecrypticace commented Sep 15, 2025

Unfortunately for backwards compatibility purposes (with loadConfig at least) we can't switch things to use import(…) because there's baked in knowledge that the config is loaded synchronously for v3.

This PR does two things:

  • Defers to require(…) which allows newer versions that support require(esm) to work natively. This works around the need to switch to import(…) for those versions.
  • Allows newer versions of postcss-load-config enabling better ESM+TypeScript support for PostCSS configs in the CLI.

We support v4, v5, and v6 of postcss-load-config simultaneously so any of those versions should work. I've verified that newer node versions seem to install v6 while earlier ones like Node v14 install v4 of postcss-load-config. So this should be a backwards compatible change.

  • needs tests for import.meta.resolve(…)
  • needs tests for ESM postcss configs

Fixes #14152
Fixes #14423

@thecrypticace thecrypticace force-pushed the fix/esm-fixes branch 3 times, most recently from a087363 to c37f9c0 Compare September 15, 2025 20:46
@thecrypticace thecrypticace marked this pull request as ready for review September 15, 2025 21:01
@thecrypticace thecrypticace requested a review from a team as a code owner September 15, 2025 21:01
@thecrypticace thecrypticace force-pushed the fix/esm-fixes branch 2 times, most recently from 9aa5207 to a3eab0d Compare September 16, 2025 16:12
Copy link
Member

@RobinMalfait RobinMalfait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I think we can drop that extension check.

Jiti hotfixed the incompatibility in 1.21.7 so we can safely drop this code.

This fixes an issue where `import.meta.*` can’t be used at all. At least with this newer node versions that support `require(esm)` *can* even if top-level await isn’t usable.

Unfortunately switching this to import(…) and thus returning a promise is a breaking change for IntelliSense, Prettier, and any other potential clients using the public `loadConfig` API.
@thecrypticace thecrypticace merged commit ba55a44 into v3 Sep 16, 2025
28 checks passed
@thecrypticace thecrypticace deleted the fix/esm-fixes branch September 16, 2025 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants