Skip to content

Commit deca13e

Browse files
committed
fix(mrt): add exports map with ESM-flavoured type declarations
`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`).
1 parent 6008059 commit deca13e

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

packages/material-react-table/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@
2727
"main": "dist/index.js",
2828
"module": "dist/index.esm.js",
2929
"typings": "dist/index.d.ts",
30+
"exports": {
31+
".": {
32+
"module": "./dist/index.esm.js",
33+
"import": {
34+
"types": "./dist/index.d.mts",
35+
"default": "./dist/index.js"
36+
},
37+
"require": {
38+
"types": "./dist/index.d.ts",
39+
"default": "./dist/index.js"
40+
}
41+
},
42+
"./*": "./*"
43+
},
3044
"files": [
3145
"dist",
3246
"locales",

packages/material-react-table/rollup.config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export default [
3939
},
4040
{
4141
input: './dist/types/index.d.ts',
42-
output: [{ file: `./${pkg.typings}`, format: 'esm' }],
42+
output: [
43+
{ file: `./${pkg.typings}`, format: 'esm' },
44+
{ file: './dist/index.d.mts', format: 'esm' },
45+
],
4346
plugins: [
4447
del({
4548
hook: 'buildEnd',

0 commit comments

Comments
 (0)