Skip to content
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

ESM: use .js extension with type: module in package.json #972

Merged

Conversation

denysoblohin-okta
Copy link
Contributor

@denysoblohin-okta denysoblohin-okta commented May 31, 2022

Better way to fix ES module for Node.js and browser environments and also for using with Jest:

  • Keep '.js' extension instead of '.mjs'
  • Add small 'package.json' file to dist/esnode and dist/esbrowser with contents { "type": "module" }

Without this change need to use moduleNameMapper in Jest config with entry:

'^broadcast-channel$': '<rootDir>/node_modules/broadcast-channel/dist/esnode/index.mjs'

@denysoblohin-okta
Copy link
Contributor Author

@pubkey Any thoughts on PR?

@pubkey
Copy link
Owner

pubkey commented Jun 1, 2022

@denysoblohin-okta does this conflict with your pr #962 ?

To be honest, I have no personal opinion, I have just given up on ever having 'standard' way to distribute browser&node npm modules. The correct way changes once a year and you will always find a build tool that is not compatible with how the code is distributed.

Shouldn't this be a PR to Jest because they should support mjs files?

@denysoblohin-okta
Copy link
Contributor Author

It does not conflict with #962, it does the same thing but with support of how Jest resolves ES modules

@pubkey pubkey merged commit bbde03e into pubkey:master Jun 1, 2022
@pubkey
Copy link
Owner

pubkey commented Jun 1, 2022

Merged and released in 4.13.0

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