-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
ESM importing a CommonJS calls getters #35859
Comments
/cc @guybedford |
So this is by design of the implementation of ES modules in that all named export bindings must be populated upfront and can't be getters themselves. So we do call getters when populating these for the CJS module representation. On the other hand one option might be to not detect In most cases, though surely you would want this to be a named export? Is I'm also not sure we should be making breaking changes to the named exports algorithm at this stage of the game too. So I'm somewhat on the fence if we should support this case, but it's worth considering the options. |
If it were any other dependency, that wouldn't be an issue. But in this case, this dependency requires build tools to be installed to build a native binary (https://www.npmjs.com/package/pg-native). It's not something one should be forced to do, if we don't plan on using that part of the library. TBH I would also like to see a change in how the But what about other packages that may be using a similar pattern? |
I've posted a fix PR in #35871 for this. I think it does make sense to ignore these exports. |
@avaly Can we close this now? Can you confirm the merged PR fixed your issue? |
I've tried just now |
Thanks for checking this again, created a new PR at #35928. |
Fixed in #35928. Thanks again for the quick reports. |
What steps will reproduce the bug?
Install
pg
npm dependencyRun the following module:
How often does it reproduce? Is there a required condition?
It always reproduces. The imported module needs to be a CommonJS module with getters.
In this case
pg
exports a getter that lazily tries to load another npm package: https://github.com/brianc/node-postgres/blob/master/packages/pg/lib/index.js#L32-L55What is the expected behavior?
What do you see instead?
Additional information
This change was introduced in #35249
The text was updated successfully, but these errors were encountered: