Add exports map with ESM-flavoured type declarations for node16/nodenext - #1525
Open
markedwards wants to merge 1 commit into
Open
Add exports map with ESM-flavoured type declarations for node16/nodenext#1525markedwards wants to merge 1 commit into
markedwards wants to merge 1 commit into
Conversation
|
@markedwards is attempting to deploy a commit to the Kevin Vandy OSS Team on Vercel. A member of the Team first needs to authorize it. |
`moduleResolution: node16`/`nodenext` consumers currently read `dist/index.d.ts` in a CommonJS context, so named imports/types resolve incorrectly. Add an `exports` map that routes types per condition: `import` → a new `dist/index.d.mts` (read as ESM), `require` → the existing `dist/index.d.ts`. Runtime resolution is unchanged — both `import` and `require` `default` point at the existing CJS build (`dist/index.js`), and a `"module"` condition points at the ESM build so bundlers keep the tree-shakeable output (matching the existing `module` field; Node ignores this condition). The `.d.mts` is a second output of the existing `rollup-plugin-dts` step — no copy step, no new dependency. `"./*"` preserves deep imports (e.g. `locales`).
markedwards
force-pushed
the
fix/add-exports-map
branch
from
August 10, 2026 14:56
41e6284 to
deca13e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Under TypeScript's
moduleResolution: node16/nodenext,material-react-tableresolves to the wrong type shape. Types-only cause: the package has noexportsfield, and its singledist/index.d.tsis read as CommonJS when the package has no"type": "module"— regardless of which condition resolved it — so ESM consumers get CommonJS-shaped declarations and named imports/types resolve incorrectly.Fix
Add an
exportsmap that routes types per condition, and emit an ESM-flavoureddist/index.d.mts. Runtime resolution is deliberately unchanged:importandrequireboth resolve to the CJS build (dist/index.js) — exactly whatmainresolved to before, so there is no runtime change for Node consumers.modulecondition (honoured by webpack/Vite/etc., ignored by Node) keeps the tree-shakeable ESM build for bundlers, matching the pre-existingmodulefield. Bundlers that don't honour it fall back toimport→ CJS.dist/index.d.mtsis produced as a second output of the existingrollup-plugin-dtsstep — identical bundled declarations, no copy step, no new dependency.main/module/typingsare retained and"./*"preserves deep imports (e.g.locales), so the change is additive.Compatibility — please review before choosing a release type
Introducing an
exportsmap restricts the package to its declared entry points."./*": "./*"preserves arbitrary subpaths (dist/*,src/*,package.json, and any file imported with an extension), so the common surfaces are unaffected. One raw-Node pattern does change:require('material-react-table/locales/<lang>')resolved tolocales/<lang>/index.jsbefore (CJS directory resolution via each locale's ownpackage.json); with theexportsmap it becomesERR_PACKAGE_PATH_NOT_EXPORTED, becauseexportspatterns don't perform directory/index resolution. Bundler consumers (webpack/Vite/Next/etc.) are unaffected — they directory-resolve the subpath themselves — and ESMimportof an extensionless locale subpath was already unsupported. So this only affects code doing a raw-Noderequire()of a locale directory.If you'd like to preserve that path (and keep this non-breaking), add a locale subpath entry — verified to restore both
requireandimportoflocales/<lang>to the pre-exportstarget:I left it out of this PR to keep it focused on the type-resolution fix — happy to add it if you'd prefer. Either way, the semver/release decision is yours.