-
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
Static methods from classes exported as default are not made available by __exportStar #472
Comments
This is because the However, other bundlers are inconsistent in which exports work in which cases (named vs. star import, also static vs. dynamic binding). I consider this a bug in other bundlers (all other bundlers have this problem). I'm documenting this behavior in the examples below. I have used For
For
Just changing to Changing this would also have the undesirable side effect of adding lots of extra properties to the exports object which may confuse people. Most objects have the I suspect trying to address all of this will have a noticeable performance penalty on the startup time of the generated modules. This is unfortunate but I'm not sure what to do about that. |
Thanks for going into so much detail, I hadn't realised there would be so much inconsistency with imports. My mental model is that One interesting nuance is that, if the entrypoint is plain javascript instead of typescript:
then, when built with |
Sort of, although not in the pure ECMAScript module world. The import foo from 'module'
import { default as foo } from 'module' Doing this does not get the property import { foo } from 'module' In case it helps: you can import both import { default as a, foo as b } from 'module' What's happening here is that esbuild is basically doing the following conversion for you to adapt this CommonJS module to ECMAScript: module.exports = Hey
export default Hey
export const hello = Hey.hello This results in two export names,
Running the export through
If you prefer |
esbuild index.ts --bundle
produces javascript which, when executed, throws this error:This appears to be because
esbuild
passes thehey
module through the__toModule
function, which fails to identify thestatic hello()
function as a valid function exposed on the module namespace, becausefor (let key in module)
in__exportStar
will not iterate overhello
as a key of the module.I wonder if this is considered a bug in
esbuild
, and if so, whether iterating overObject.getOwnPropertyNames(module)
instead might be a valid solution.The text was updated successfully, but these errors were encountered: