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

Registering customization hooks via --require results in double registration #52377

Open
Flarna opened this issue Apr 5, 2024 · 0 comments
Open
Labels
loaders Issues and PRs related to ES module loaders module Issues and PRs related to the module subsystem.

Comments

@Flarna
Copy link
Member

Flarna commented Apr 5, 2024

The current recommendation to install customization hooks is to use --import.

But --import is still marked as experimental therefore not the preferred thing to use in production.

If I use the stable alternative --register the loader hooks are installed twice.

Easy to reproduce:

// loader.mjs
export async function resolve (specifier, context, parentResolve) {
    console.log('execArgv', process.execArgv);
	return await parentResolve(specifier, context);
}

// register.js
const { register } = require('node:module');
const { pathToFileURL } = require('node:url');

const url = pathToFileURL('./loader.mjs');

console.log('registering', url.href);
register(url);

// main.mjs
console.log("hello");

run with --require results in

node --require ./register.js  main.mjs  
registering file:///C:/work/node-double-loader/loader.mjs
registering file:///C:/work/node-double-loader/loader.mjs
execArgv [ '--require', './register.js' ]
execArgv [ '--require', './register.js' ]
hello

run with --import:

registering file:///C:/work/node-double-loader/loader.mjs
execArgv [ '--import', './register.js' ]
hello

I guess the --require argument gets forwarded to the internal Worker (along with env and other command line args) and in contrast to --import this seems to have an effect.

Not sure if the problem is the different behavior of --require vs --import in Worker.

But in general I think we should not blindly forward and command line args to the internal hooks worker.

Edit: Thinking once more I think we should forward env/--require/... configs to the internal worker. People migth want to get e.g. Otel into this thread to capture traces.

@Flarna Flarna added loaders Issues and PRs related to ES module loaders module Issues and PRs related to the module subsystem. labels Apr 5, 2024
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

No branches or pull requests

1 participant