-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Do not differ between CommonJS and ESM builds #2571
Comments
This sounds more like a bug in Parcel: they should follow the same convention followed by webpack and include the
No, because both target different environments (Node vs Browser) so it makes sense to optimize them differently |
Tree shaking doesn't work with HMR, hence ESM is useless when developing with HMR and transpiling ESM to CommonJS, which is ultimately used in the final build, only slows the build down. You can't assume ESM is bundler and CJS is Node anymore; Node supports ESM loading. Instead, the If you really want to force Parcel to unnecessarily transpile ESM in development, setting the |
👍 (The modern way for different builds for esm/cjs/node is the |
@posva Would adding the |
If I recall correctly, using "browser" for the ESM breaks other things because it's not a browser module, it contains environment variables |
As far as I know, only bundlers support the |
No, bundlers are not the only ones, some cdns use it too |
One solution would be adding |
What problem does this feature solve?
Parcel 2 breaks on Vue with HMR because it expects
__VUE_HMR_RUNTIME__
to be defined in the global scope. This is only defined in the ESM build because Vue assumes all bundlers will use ESM. However, to save Babel compilation time in development, Parcel 2 uses the CommonJS version, defined by"main"
inpackage.json
, meaning the HMR runtime added by the Vue transformer breaks. This issue was found in parcel-bundler/parcel#5325.What does the proposed API look like?
Code that functions differently with CommonJS and ESM is unusual and is arguably an antipattern. Creating a CJS version for bundlers and adding that to
"main"
or adding the HMR runtime to the existing CJS build would fix the issue.The text was updated successfully, but these errors were encountered: