-
Notifications
You must be signed in to change notification settings - Fork 21
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
SourceMapNode is not a constructor #155
Comments
Hello @bashmish, thank you for the issue and sorry for the delay. I'm not sure if I understood the problem correctly. Indeed, the typings of As you can see here: link, the module exports the class like this: exports.default = NodeSourceMap; But it should be: exports = NodeSourceMap; in order for the class to be imported as the default member. As you mentioned, we prefer Node with ESM, so I'm wondering if there's some scenario where the import is modified by a transpiler. Could you provide a reproduction case for us to investigate? Nevertheless, we are certainly available to handle the scenario as soon as we understand it :) |
@edoardocavazza I ran into similar issues just yesterday, so good timing, since it gave me more knowledge to answer :) Indeed there is a transpiler somewhere which dynamically patches ESM modules to be consumed by CommonJS modules. I don't know exactly how to solve it yet, I might still require a fix on your side, but for the time being I'll close this issue. Thank you so far! |
I'd like to reopen this. Did a bit more digging into this problem and found out it's the well-known issue with default exports CJS/ESM interop which can't be solved by tools automatically in all cases. There is a good explainer here https://esbuild.github.io/content-types/#default-interop In my case I end up having In your case the import sourceMapDefault from '@parcel/source-map';
const { default: SourceMapNode } = sourceMapDefault; This is a good workaround for apps, but for libs I think there is a better one which can solve it both for you and me. On top of that the TypeScript required you to copy over some types into This problem and workarounds for it are also discussed in this esbuild issue. |
This is similar to #150
You have the following code in
estransform
:which breaks when used in Node, because default export is already an object
SourceMapNode
, so extra destructuring makes it undefined leading toIf I understood correctly from you previous answer, you have a browser ESM usage mainly, not Node like in my case.
Probably you have some compatibility mode for default exports which makes it work like this.
The original package has only regular default export https://cdn.jsdelivr.net/npm/@parcel/source-map@2.1.1/index.d.ts, so I think it's worth supporting such usage.
The text was updated successfully, but these errors were encountered: