Fix native ESM config loading in v3 #18938
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Unfortunately for backwards compatibility purposes (with
loadConfig
at least) we can't switch things to useimport(…)
because there's baked in knowledge that the config is loaded synchronously for v3.This PR does two things:
require(…)
which allows newer versions that supportrequire(esm)
to work natively. This works around the need to switch toimport(…)
for those versions.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 ofpostcss-load-config
. So this should be a backwards compatible change.import.meta.resolve(…)
Fixes #14152
Fixes #14423