-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support for hybrid packages cjs/esm #840
Comments
I suspect this is a config issue. @dubzzz can you try passing --format=esm when you run esbuild? By default esbuild will set module to cjs when building for mode platform as documented here: https://esbuild.github.io/api/#format |
Oh, thanks a lot. I'll definitely retry with it. I'll let you know. I was expecting to have the same behaviour as the others by default without any specific option but perfect if it works. |
@osdevisnot It seems to give the exact same result when I use: --- esbuild main.js --bundle --platform=node --outfile=dist/main.node.js
+++ esbuild main.js --bundle --platform=node --format=esm --outfile=dist/main.node.js The build still imports the commonjs version. |
This is likely deliberate behavior instead of a bug. There are some differences between the
Here's the issue that resulted in this change, with a lot of discussion: #363. |
Thanks a lot for the quick response. Perfect 👌 I'm closing the issue |
@evanw Does esbuild take into account |
No it doesn’t yet. I still need to add that but given that the |
Oh great! Thanks a lot your answers. I'll track the issue just to follow next moves |
I recently wanted to check how
esbuild
would deal with hybrid packages. By hybrid I mean packages handling both CommonJS and ES Modules at the same time.And it seems that the behaviour diverges from other bundlers and also from node when using
platform=node
.Here is what I tried to do:
I took
fast-check
as an example of such package and tried to run the following snippet:Content of main.js* (*main.mjs for the case '.mjs extension')
Here are the results I got with multiple bundlers (including esbuild):
*In order to run the repro locally, you have to run:
yarn && yarn start && echo out.txt
It seems that contrary to other setups, the one based on esbuild with platform=node imports the commonjs version.
My tests have been executed against esbuild@0.8.47 and esbuild@0.8.48.
I don't exactly know if it should be considered as expected or not, so I open the issue just in case it could help.
The text was updated successfully, but these errors were encountered: