Replies: 2 comments 5 replies
-
Thanks! covert CJS to ESM is not that easy, there are a lot of edge cases if you want every packages work correctly. But the basic approach is using the esbuild plugin system: remark the require calls as external then replace them manually with the esm syntax. the hardest part is looking up those external Line 794 in a546b8b |
Beta Was this translation helpful? Give feedback.
-
One of the "funniest" things when you try to convert peerDeps to standalone ESM modules is that e.g.: esbuild generates different imports in userland code when we This aside, I'd also love a cli a tool which can do something like what esm.sh does, but on-prem, locally. (on NodeJS) |
Beta Was this translation helpful? Give feedback.
-
First of all, this is awesome work and website! For the first time, I am able to use react in non-bundled true ESM modules.
I am curious how these ESM modules are generated, since for example, react has officially publishes only CJS and UMD format. I looked at the MJS file and found the following header, which led me to investigate ESBuild.
However, when I tried to run ESBuild with
--format=esm
on react-dom.development.js, it gave the following error:This is different than the react-dom.development.js hosted on esm.sh, which has successfully converted require in CJS to import in ESM:
I would like to learn how I can convert CJS modules which resides in my local node_modules directory to ESM, without bundling. Ideally the tooling can be smart enough to walk down the import tree to convert dependent CJS to ESM as well so it is purely in ESM.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions