Skip to content

Incorrect parentURL for registerHooks when using require(esm) #60973

Description

@sxzz

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions