Skip to content
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

TypeError: Cannot read property 'ColumnNames' of undefined #909

Closed
moltar opened this issue Mar 3, 2021 · 6 comments
Closed

TypeError: Cannot read property 'ColumnNames' of undefined #909

moltar opened this issue Mar 3, 2021 · 6 comments

Comments

@moltar
Copy link

moltar commented Mar 3, 2021

I am not sure if the issue is with esbuild or the underlying library, but I am running into a peculiar error for which I have a repro here:

https://github.com/moltar/zapatos-issue-10

Transpiling with tsc works fine.

Reference issue in the library repo: jawj/zapatos#75

Thank you!

@evanw
Copy link
Owner

evanw commented Mar 3, 2021

The problem happens when node_modules/zapatos/db.mjs (an ESM file) imports node_modules/zapatos/db.js (a CommonJS file). I think the underlying issue is #532, which is already tracked. Basically there are two conflicting approaches for handling importing a CommonJS file into an ESM file. Some JavaScript tools do this one way and other JavaScript tools do this another way. It's a big mess.

The way node works is that the default export is always equal to the value of the CommonJS file's module.exports property without any exceptions. Some other JavaScript tools (but not node) support CommonJS files that have been converted from ESM format to CommonJS format. These ones are marked by setting module.exports.__esModule to true. For these modules, all properties on module.exports behave like named exports as if the file was in ESM format. And if there is no module.exports.default property, then there is no export named default.

So this should be considered a bug in esbuild in that the behavior isn't matching node. But it's not super straightforward to fix this because a trivial fix would break esbuild's ESM-to-CommonJS transform which esbuild relies on internally. Webpack has an approach where they try to support both of these behaviors and use heuristics to determine which approach to apply when. I assume esbuild will have to do something like that.

@moltar
Copy link
Author

moltar commented Mar 3, 2021

@evanw thank you for your in-depth explanation! I really appreciate all of the effort and community management you put into this. 🙌🏼

Shall we close this in favor of #532 then?

@evanw
Copy link
Owner

evanw commented Mar 3, 2021

Sure, sounds good. I greatly appreciate having a real-world example of this problem in practice though. So thank you very much for taking the time to put together a repro.

@evanw
Copy link
Owner

evanw commented Mar 4, 2021

Closing in favor of #532.

@evanw evanw closed this as completed Mar 4, 2021
@evanw
Copy link
Owner

evanw commented Mar 4, 2021

I believe this should be working now as of version 0.8.55. Please let me know if that's not the case.

@moltar
Copy link
Author

moltar commented Mar 4, 2021

That does indeed fix the issue! Thank you so much for fixing this so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants