Skip to content

Conversation

reekystive
Copy link

Description

Add "module" and "exports" fields to package.json to provide better ESM support.

Changes

  • Add "module": "./esm/index.js" field to allow bundlers to use the ES modules version

  • Add "exports" field to provide correct entry points for different import methods:

    • "import": ESM module imports
    • "require": CommonJS imports
    • "types": TypeScript type definitions
  • package.json: Updated the main field to use a relative path, added a module field for ES module entry point, and updated the types field to use a relative path.

  • package.json: Added an exports field to specify different entry points for import, require, and types.

Benefits

  • Improved compatibility with modern bundlers
  • Support for Node.js dual package specification
  • Clearer distinction between ESM and CommonJS entry points
  • Follows modern JavaScript package best practices

Breaking Changes

None, this change is fully backward compatible.

@haakonflatval-cognite
Copy link

@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)

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