Skip to content

Serve ESM type declarations to ESM importers of @tailwindcss/postcss#20228

Merged
RobinMalfait merged 2 commits into
tailwindlabs:mainfrom
truffle-dev:fix/postcss-esm-types-condition
Jun 12, 2026
Merged

Serve ESM type declarations to ESM importers of @tailwindcss/postcss#20228
RobinMalfait merged 2 commits into
tailwindlabs:mainfrom
truffle-dev:fix/postcss-esm-types-condition

Conversation

@truffle-dev

Copy link
Copy Markdown
Contributor

Summary

Fixes #20219.

The @tailwindcss/postcss exports map serves the CJS-shaped dist/index.d.ts (export = _default) for both the import and require conditions, while the correct ESM declaration file dist/index.d.mts (export { _default as default }) is built and published but never referenced. Type checkers that treat the import condition as ESM reject the default import with TS1192 — concretely, deno check on Deno 2.8.3+ (which ships TypeScript 6.0) fails on import tailwindcss from "@tailwindcss/postcss".

This splits the export entry into per-condition types blocks so ESM importers resolve index.d.mts and CJS consumers keep index.d.ts — the same shape @tailwindcss/vite already uses ("types": "./dist/index.d.mts").

Two notes on the issue as filed:

  • Stock tsc with NodeNext does not reproduce the error (declaration file format follows the file extension and package type, not the matched condition), so I didn't take the suggested export =export default change in index.d.ts — that would break CJS consumers, and the correct ESM declarations already ship.
  • @tailwindcss/node has the same single-types exports shape; happy to follow up there if you want parity.

Test plan

Against @tailwindcss/postcss@4.3.0 with the published exports map, then again with only this package.json change applied to the installed package:

# Deno 2.8.3 (TypeScript 6.0), nodeModulesDir: auto
deno check main.ts   # before: TS1192 "Module ... index.d.ts has no default export" — after: passes
# typescript@6.0.0-dev (NodeNext), one ESM importer + one .cts require importer
tsc --noEmit         # passes both before and after (no regression for npm consumers)

@arethetypeswrong/cli:

published 4.3.0 with this change
node16 (from ESM) 🎭 Masquerading as CJS 🟢 (ESM)
node16 (from CJS) 🟢 (CJS) 🟢 (CJS)
bundler 🟢 🟢

The exports map served the CJS-shaped `dist/index.d.ts` (`export =`)
for both the `import` and `require` conditions, while the correct
ESM declaration file `dist/index.d.mts` was built and published but
never referenced. Type checkers that treat the import condition as
ESM (TypeScript 6.0 via `deno check` in Deno 2.8.3+) reject the
default import with TS1192.

Split the export entry into per-condition blocks so ESM importers get
`index.d.mts` and CJS consumers keep `index.d.ts`, mirroring the
shape `@tailwindcss/vite` already uses.

Fixes tailwindlabs#20219
@truffle-dev truffle-dev requested a review from a team as a code owner June 12, 2026 14:12
@greptile-apps

greptile-apps Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — the exports map change is minimal, exactly parallels how other packages in this repo are structured, and both generated declaration files already exist in the published artifact.

Both dist/index.d.mts and dist/index.d.ts are already produced by the existing tsup build (ESM entry from src/index.ts, CJS entry from src/index.cts), so no build changes are needed. The restructuring only affects how type checkers resolve declarations under each module condition — CJS consumers see no change, and ESM consumers get the correctly-shaped declaration file they were previously missing.

No files require special attention. The single package.json export map change is straightforward, and the CHANGELOG entry is accurate.

Reviews (1): Last reviewed commit: "Add changelog entry" | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 795655e0-0799-4a97-b349-6c8a6899590d

📥 Commits

Reviewing files that changed from the base of the PR and between aaf8ad6 and c9fae30.

📒 Files selected for processing (1)
  • CHANGELOG.md
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

Walkthrough

This PR updates the export map in the @tailwindcss-postcss package to use conditional sub-exports. The exports["."] field is restructured so that both ESM (import) and CommonJS (require) conditions now specify their own types and default entry points separately, rather than using a single flat types field. This ensures type definitions and runtime entries are resolved correctly for each module format.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: serving ESM type declarations to ESM importers of @tailwindcss/postcss by updating the exports map.
Description check ✅ Passed The description comprehensively explains the issue, the solution, testing approach, and includes notes on why alternative approaches were not taken.
Linked Issues check ✅ Passed The PR fulfills the requirements from #20219 by updating package.json exports to serve ESM type declarations (index.d.mts) to ESM importers while maintaining CJS declarations for require conditions.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the export map for @tailwindcss/postcss per the linked issue; no unrelated modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@RobinMalfait RobinMalfait enabled auto-merge (squash) June 12, 2026 14:28

@RobinMalfait RobinMalfait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@RobinMalfait RobinMalfait merged commit 522288c into tailwindlabs:main Jun 12, 2026
8 checks passed
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.

types: export = in @tailwindcss/postcss contradicts exports.import in package.json

2 participants