Skip to content

Add module and exports field to package.json#2858

Open
lennondotw wants to merge 1 commit intoiamkun:devfrom
lennondotw:patch-1
Open

Add module and exports field to package.json#2858
lennondotw wants to merge 1 commit intoiamkun:devfrom
lennondotw:patch-1

Conversation

@lennondotw
Copy link
Copy Markdown

@lennondotw lennondotw commented Apr 15, 2025

Summary

Add module and exports fields to package.json for proper ESM support.

Changes

  • Add "module": "./esm/index.js" for bundler ESM resolution
  • Add "exports" map covering root, ./esm, ./plugin/*, ./esm/plugin/*, ./locale/*, ./esm/locale/*
  • Normalize main and types paths to use relative ./ prefix

Benefits

  • Modern bundlers (Vite, webpack 5, Rollup) can resolve ESM entry points correctly
  • Node.js conditional exports work for both import and require
  • Fully backward compatible — no breaking changes

@haakonflatval-cognite
Copy link
Copy Markdown

@iamkun I'm seeing problems in some ESM-projects projects I'm working on that require extra patching of import paths from day.js in our config files due to malformed/missing export fields in the package.json, which is what this PR is trying to address. It would be greatly appreciated if you could consider merging this or one of the similar ones (e.g. https://github.com/iamkun/dayjs/pull/2543/files)

Add ESM entry point and Node.js exports map for proper dual
CJS/ESM resolution by modern bundlers and Node.js.
@lennondotw
Copy link
Copy Markdown
Author

Rebased on latest dev, squashed to a single commit, and cleaned up the exports map — root entry now properly resolves ESM imports (no more "import": null), and removed the unintended packageManager field.

@iamkun would appreciate a look when you have a moment — this addresses the ESM import issues mentioned by @haakonflatval-cognite above.

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.

2 participants