evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
37.72k stars 1.11k forks source link

default export interpretation #3642

Open ex37 opened 5 months ago

ex37 commented 5 months ago

I have some complaints about the way of choosing either Node or Babel interpretation, which is described here: https://esbuild.github.io/content-types/#default-interop

I have a typescript front end app, which is sort of a monorepo, and is divided into packages. Packages are using "type": "module" in their package.json files', and I use it for the exports / imports functionality together with resolvePackageJsonExports typescript flag.

The code is definitely not intended to run in Node, in fact platform is set to browser in esbuild's config, but cause of the way it's currently interpreted, it causes problems when importing different front end libraries.

What I suggest is either of the following:

Thanks.

evanw commented 5 months ago

As is mentioned in the documentation you linked to, this behavior was deliberately copied from Webpack. I'd like to keep the behavior consistent with Webpack so packages can standardize on some behavior instead of adding to the confusion by having the ecosystem fragment further.

ex37 commented 5 months ago

@evanw while I agree with you on standardizing behavior, there are still older and not so frequently maintained packages in the wild, so at least having a possibility to force certain behavior using plugins or configuration options would be really helpful, otherwise the only solution is to manually patch packages. And if you are not so interested in this, maybe you'll welcome a PR?