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

Regression when updating to 0.14.22. #2026

Closed
n1xx1 opened this issue Feb 17, 2022 · 4 comments
Closed

Regression when updating to 0.14.22. #2026

n1xx1 opened this issue Feb 17, 2022 · 4 comments

Comments

@n1xx1
Copy link

n1xx1 commented Feb 17, 2022

I'm having some problems importing ESModule (that declare __esModule as true but use requires) in the newest version of esbuild. Basically the default import is considered as being a * import for some reasons. I haven't had time to check every single version but 0.14.22 doesn't work as expected, 0.14.3 works as expected.

test.ts

import createImagePlugin from "draft-js-image-plugin";
console.log(createImagePlugin);

Output with 0.14.22

$ esbuild --format=esm --bundle --platform=browser  test.ts > out.js && node out.js
{ Image: [Function: Image2], default: [Function (anonymous)] }

Output with 0.14.3

$ esbuild --format=esm --bundle --platform=browser  test.ts > out.js && node out.js
[Function (anonymous)]

Any ideas if it's an issue with my setup instead?
Thank you!

@hyrious
Copy link

hyrious commented Feb 17, 2022

Did you set "type": "module" in your package.json? It will make the assumption that the code runs on node.js, and esbuild reflects the node behavior by giving you everything on default import.

Also see #2023.

@n1xx1
Copy link
Author

n1xx1 commented Feb 17, 2022

Yes I do have "type": "module". How can I make esbuild not wrap the library to mimic the nodejs behaviour?

@evanw
Copy link
Owner

evanw commented Feb 17, 2022

This happens because esbuild now behaves the same as Webpack in this case, and Webpack also does the same thing here. Setting "type": "module" in your package.json means "I need to use node's behavior" for both Webpack and esbuild. If you don't need node's behavior, then just remove "type": "module" from your package.json. Or you can keep node's behavior and access createImagePlugin.default instead.

@evanw
Copy link
Owner

evanw commented Feb 18, 2022

I just published some documentation about this here: https://esbuild.github.io/content-types/#default-interop. It describes what the problem is, some background about where the problem comes from, and the heuristics esbuild uses to address this problem. This behavior is by design and is critical for Webpack and Node compatibility.

Closing as "working as intended."

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

3 participants