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 packaging in ESM environment #5

Merged
merged 5 commits into from
Oct 20, 2023
Merged

Conversation

Holi0317
Copy link
Contributor

Hello 👋🏽

This package cannot be imported in ESM environment even it says it should work in package.json.
For example, if the downstream consumer has type: "module" in their package.json, the import will fail with ERR_MODULE_NOT_FOUND when the entry tries to resolve internal modules:

image

This can be solved by adding .js suffix to the import path and specify moduleResolution to node16 in tsconfig to enforce this rule.

I am also adding a ESM-only warning in the README, copied from https://github.com/remarkjs/remark-directive because it seems the remark plugin ecosystem is pretty much ESM-only now.
But I am not sure if this package will work in deno or in the browser, through esm.sh so I didn't copy those instruction over.

After the change, the build passes arethetypeswrong check.

Before After
Screenshot 2023-10-19 at 12-27-18 Are The Types Wrong image

Some reference reading for this ESM issue:

Got following warning previously:
Option 'module' must be set to 'Node16' when option 'moduleResolution' is set to 'Node16'
@myl7 myl7 self-requested a review October 20, 2023 01:33
@myl7 myl7 merged commit a97b62b into myl7:main Oct 20, 2023
1 check passed
@myl7
Copy link
Owner

myl7 commented Oct 20, 2023

Included in v2.1.2

Thanks for the catch and enclosed standard ESM packaging method!

I would later check all my other JS/TS packages with the tool arethetypeswrong.

@Holi0317
Copy link
Contributor Author

Thanks a lot!

ESM is really a hard problem in JS ecosystem now hahaha.

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