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

[Feature]: Support Native ESM #717

Closed
shun-shobon opened this issue Apr 19, 2023 · 8 comments · Fixed by #880
Closed

[Feature]: Support Native ESM #717

shun-shobon opened this issue Apr 19, 2023 · 8 comments · Fixed by #880

Comments

@shun-shobon
Copy link

shun-shobon commented Apr 19, 2023

Describe

Hello. Thank you for developing this wonderful library.

Currently, this library provides both CommonJS format files and ES Module format files. However, the ESM files are only specified as "module" in package.json. "module" is not supported by Node.js, and Node.js running as ESM cannot import ESM files from this library.

To enable Node.js to import ESM files, you should add "type": "module" to package.json and provide CommonJS format files as .cjs.

Solution

First, add "type": "module" to package.json to indicate that the library is provided by ESM. Next, rewrite the file extensions provided by CommonJS from .js to .cjs and the file extensions provided by ESM from .esm.js to .js. This will work in CommonJS by auto-completion of main and extensions, and in ESM by directly specifying index.js. This should also work well in TypeScript with "moduleResolution": "node16" set.
Conditional exports would also be better supported, but since there are so many subdirectories in this library, I think it may not be necessary to do this at first.

Minimal sample repository URL

No response

Additional context

I would like to be able to import ESM and CommonJS files in the standard Node.js functionality. I would love to work on this issue and would love to send you a PR!

@Lord-Valen
Copy link

I suspect that this is the cause of TS2307 when using node16 module resolution.

@user1m
Copy link

user1m commented Jul 7, 2023

any progress on this? would be happy to support as well. running into issues using this lib ina vite ESM SSR project

Screen Shot 2023-07-07 at 4 40 15 PM

related:

UPDATE: this comment solved my issue w/ building via vite: #509 (comment)

@LorenzoBloedow
Copy link
Contributor

Having this problem with the Vercel integration of Astro.js, during SSR.

Happy to help as well!

@LorenzoBloedow

This comment was marked as off-topic.

@stivncastillo

This comment was marked as off-topic.

@LorenzoBloedow

This comment was marked as off-topic.

@stivncastillo

This comment was marked as off-topic.

@dvnrsn
Copy link

dvnrsn commented Nov 14, 2023

For me it works as long as I append "index.js" to all of my imports which is annoying but workable 🤔

import { AiOutlineMenu } from "react-icons/ai/index.js";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants