node icon indicating copy to clipboard operation
node copied to clipboard

Incorrect `parentURL` for `registerHooks` when using `require(esm)`

Open sxzz opened this issue 1 month ago • 1 comments

Version

v25.2.1

Platform

Darwin Kevins-MacBook-Pro.local 25.1.0 Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

Reproduction: https://github.com/sxzz/node-loader-require-esm

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

N/A

What is the expected behavior? Why is that the expected behavior?

Expected: The parentURL of require(esm) should include the query ?test, matching the value of import.meta.url.

{
  specifier: './esm.mjs',
  url: 'file:///x/node-loader-require-esm/esm.mjs',
  parent: 'file:///x/node-loader-require-esm/mod.mjs?test'
}

Actual:

{
  specifier: './esm.mjs',
  url: 'file:///x/node-loader-require-esm/esm.mjs',
  parent: 'file:///x/node-loader-require-esm/mod.mjs'
}

What do you see instead?

{
  specifier: './mod.mjs?test',
  url: 'file:///Users/kevin/Developer/reproduction/node-loader-require-esm/mod.mjs?test',
  parent: 'file:///Users/kevin/Developer/reproduction/node-loader-require-esm/main.mjs'
}
{
  specifier: 'node:module',
  url: 'node:module',
  parent: 'file:///Users/kevin/Developer/reproduction/node-loader-require-esm/mod.mjs?test' // ✅
}
{
  'import.meta.url': 'file:///Users/kevin/Developer/reproduction/node-loader-require-esm/mod.mjs?test'
}
{
  specifier: './esm.mjs',
  url: 'file:///Users/kevin/Developer/reproduction/node-loader-require-esm/esm.mjs',
  parent: 'file:///Users/kevin/Developer/reproduction/node-loader-require-esm/mod.mjs' // ❌
}

Additional information

https://github.com/sxzz/import-without-cache needs this behavior.

/cc @joyeecheung

sxzz avatar Dec 06 '25 02:12 sxzz

Thanks for the report, fix in https://github.com/nodejs/node/pull/60974

joyeecheung avatar Dec 06 '25 05:12 joyeecheung