-
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 --loader cause duplicate app load #49082
Comments
It's not a bug, it's a feature. As of 20.0.0, loaders are now executed on a separate thread, meaning importing module and setting globals no longer affects the main application thread. By doing Maybe you could share a bit more on what you are trying to achieve so we can discuss how to support your use-case? |
Our application is a kind of a profiler and we need the ability to get all the ES Modules right after the loading. If you have a better solution, maybe a more elegant way to register to ES module load event, it will be much easier for us. Thanks! |
seems to be related or even duplicate to #47880 |
You can use the I'm going to close this now if that's OK. |
Version
v20.4.0
Platform
Microsoft Windows NT 10.0.19044.0 x64
Subsystem
No response
What steps will reproduce the bug?
We use --loader to manipulate ESM sourcecode before loading and when using node v20.x, it cause duplicate application loads.
Please take a look at the following code, which is a minimal reproducer for the issue.
Files:
Now let's compare the runs for node 20 vs node 18:
Note that we do import again any loaded module during the
esm-loader.load
callback, but we excepted to get a cached module, like we get for any other import call. As you can see, that's how it worked in previous node versions and with the node.js example, we ran theesm-app.mjs
code only once.Is it a bug in node 20 or is there something we can do to prevent this duplicate import?
Thanks!
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
See above runs
What do you see instead?
See above runs
Additional information
No response
The text was updated successfully, but these errors were encountered: