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

Fix ESM importing on Node.js #208

Merged
merged 2 commits into from
Jan 30, 2024
Merged

Fix ESM importing on Node.js #208

merged 2 commits into from
Jan 30, 2024

Conversation

jaens
Copy link
Contributor

@jaens jaens commented Jan 30, 2024

Currently, Node.js always used the CommonJS version even when imported from an ES module. That's because ES modules require an exports key to be defined in package.json.

(The module key is only used by bundlers, AFAIK.)

Also, since there is no type: "module" configured, all ES modules need to have the .mjs extension (otherwise they will go through the CommonJS compatibility shim which again, will cause the import to fail). Fix that as well.

@jaens
Copy link
Contributor Author

jaens commented Jan 30, 2024

Currently, Node.js always used the CommonJS version even when imported from an ES module. That's because ES modules require an `exports` key to be defined in `package.json`.

(The `module` key is only used by bundlers, AFAIK.)

Also, since there is no `type: "module"` configured, all ES modules need to have the `.mjs` extension (otherwise they will go through the CommonJS compatibility shim which again, will cause the import to fail). Fix that as well.
@samchungy
Copy link
Owner

Thanks for the contribution!

@samchungy samchungy merged commit 794c9dc into samchungy:master Jan 30, 2024
1 check passed
@github-actions github-actions bot mentioned this pull request Feb 5, 2024
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