Open
Description
What
I suggest updating the tsup.config.ts
to include ESM format output:
format: ['cjs', 'esm'] // currently only 'cjs'
And updating package.json to include the module field and a more structured exports map that distinguishes between ESM and CJS, like this:
"main": "dist/index.js",
"module": "dist/index.mjs",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./app": {
"import": "./dist/app.mjs",
"require": "./dist/app.js",
"types": "./dist/app.d.ts"
},
"./pages": {
"import": "./dist/pages.mjs",
"require": "./dist/pages.js",
"types": "./dist/pages.d.ts"
}
}
Why this matters
- Many tools and frameworks now prefer ESM for tree-shaking and performance.
- Some environments even throw warnings or errors if a package only exports CJS.
- Supporting both CJS and ESM is the current best practice, as seen in many popular libraries.
This makes the package compatible with both ESM and CommonJS consumers and aligns with modern package publishing practices. It helps when using this library in native ESM projects (e.g., with Vite or Next.js App Router using ESM).
Compatibility
✅ This change is non-breaking
✅ Existing CommonJS users will continue to work exactly as before
✅ ESM users gain full support with no hacks
I'm happy to open a pull request with these changes just let me know if you're open to it!
Metadata
Metadata
Assignees
Labels
No labels