Skip to content

Add ESM build output and improve package exports for better module compatibility #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MTroian94 opened this issue May 16, 2025 · 2 comments

Comments

@MTroian94
Copy link

MTroian94 commented May 16, 2025

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!

@TheSGJ
Copy link
Owner

TheSGJ commented May 16, 2025

Yeah, this sounds good to me. Thanks for your helpful suggestions, and I'll also look into this. 👍

@MTroian94
Copy link
Author

Here #132 the PR associated to this issue

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

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy