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

Module.runMain causes ESM loaders in the chain to be duplicated #43753

Closed
cspotcode opened this issue Jul 10, 2022 · 3 comments · Fixed by #43763
Closed

Module.runMain causes ESM loaders in the chain to be duplicated #43753

cspotcode opened this issue Jul 10, 2022 · 3 comments · Fixed by #43763
Labels
loaders Issues and PRs related to ES module loaders module Issues and PRs related to the module subsystem.

Comments

@cspotcode
Copy link

Version

v19.0.0-nightly202207093d575a4f1b

Platform

Linux DESKTOP-5K7R6JP 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Detailed reproduction here:
https://github.com/cspotcode/repros/tree/node-loader-chaining-duplication

On node nightly, use node --loader ./loader.mjs ./index.mjs

Within index.mjs, call import {runMain} from 'module'; runMain() and then do something that uses loader hooks, such as importing or calling import.meta.resolve(). The hooks in loader.mjs have been duplicated in the chain and thus will be called more than they should.

The linked reproduction demonstrates this by implementing a loader hook that logs a message and delegates to the next hook in the chain.

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

Module.runMain understands if the loader hooks have already been initialized and does not duplicate them in the chain.

What do you see instead?

Module.runMain duplicates all loaders in the chain.

Additional information

No response

@daeyeon daeyeon added the loaders Issues and PRs related to ES module loaders label Jul 10, 2022
@aduh95
Copy link
Contributor

aduh95 commented Jul 10, 2022

/cc @nodejs/loaders

@daeyeon
Copy link
Member

daeyeon commented Jul 10, 2022

I guess that this could be fixed if we ensure initializeLoader() is called only once.

Question: runMain() seems not to be documented yet. (#32643)
If so, how should we deal with this issue?

@daeyeon daeyeon added the module Issues and PRs related to the module subsystem. label Jul 10, 2022
@JakobJingleheimer
Copy link
Contributor

I guess that this could be fixed if we ensure initializeLoader() is called only once.

That sounds good to me. Happy to tackle that part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
loaders Issues and PRs related to ES module loaders module Issues and PRs related to the module subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants