-
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
Problem with 'import * as' when importing a set of class #1073
Comments
I believe this is basically happening because esbuild is trying to faithfully emulate the way node works, and the node team made unfortunate decision that breaks a common interop scenario with cross-compiled ES modules. There is a big discussion about this here: #532. They decided that when you import a CommonJS module using an You can observe how node behaves in this situation for yourself here:
If node respected the This is happening because you are using esbuild to compile the file one-at-a-time so esbuild must treat I can think of a few options:
|
Thank you very much indeed! I think you're right and I have got to make a workaround to adopt different tools. The reason for compiling the file one-at-a-time is that I want to keep the original file structure while at the same time, I want to make use of the efficiency of esbuild. And I know it's a little bit tricky 'cause esbuild is essentially a bundler rather than an alternative for babel. |
I'm closing this issue as esbuild matches node's behavior when it's run as ESM so this is working as intended. I agree that this interop scenario is unfortunate, but that's how node works. |
Oof, just ran into this too trying to update our esbuild version (on a very large project). Can you explain the "filter out" option you mentioned? |
Object.values(lib).forEach(l => {
if (l === 'default') return;
new l();
}); |
Hmmm. Is there any option to get the legacy behavior back? So that it continues to match |
And FWIW, it only appears to be |
I want to use typescript and its dynamic feature to do something but I realized that the esbuild didn't compile the 'import * as'
For example:
and I build the thing with following configuration:
it is built successfully but when I ran dist/main.js error came out.
TypeError: l is not a constructor
this behavior is different from using tsc because esbuild warp the lib in main.ts like this:
so the values function gets the
default
and it goes errorbut tsc warp like this
the default is gone and the class is still a class rather than a getter
and I've read https://esbuild.github.io/content-types/#es-module-interop and realized that I should explicitly indicate the thing I was importing like
import lib from "./lib"
rather than "import *", but is there any way to maintain the original behavior from tsc to keep the dynamic import functional?The text was updated successfully, but these errors were encountered: