Skip to content

module: fix require(esm) error annotation with tracing subscriber - #66930

Open
CodingRule wants to merge 1 commit into
nodejs:mainfrom
CodingRule:fix/require-esm-error-annotation
Open

CodingRule wants to merge 1 commit into
nodejs:mainfrom
CodingRule:fix/require-esm-error-annotation

Conversation

@CodingRule

@CodingRule CodingRule commented Oct 22, 2026 •

Copy link
Copy Markdown

reconstructErrorStack() takes the first stack frame as the require() caller. When a module.require tracing subscriber exists, that frame is TracingChannel.traceSync, so the arrow points at a nonexistent line of the parent file:

test.cjs:568
undefined
                     ^

Pick the first frame that belongs to the parent file instead. Works for nested callers too (the first parent frame is the require() call site).

Adds a test case with a tracing:module.require:start subscriber; it fails on current main and passes with this change.

Fixes: #55350

AI disclosure

This change was made with help from an AI coding assistant (Claude Mythos 5.1). I reviewed the diff and the reasoning behind it myself.

What was verified:

  • Reproduced the bug on the current nightly (v27.0.0-nightly20261020) with a tracing:module.require:start subscriber: the arrow points at test.cjs:568 with undefined.
  • Ran reconstructErrorStack() from both the original and patched loader.js against real stacks captured from the nightly, in four shapes: plain, with subscriber, nested callers, nested with subscriber. The patched version annotates the require() call site in all four. The original fails in both subscriber cases.
  • The new test case fails on the unfixed nightly and the two existing cases still pass.
  • tools/eslint on both files with --max-warnings=0.
  • Built this branch on Windows (VS 2022 + ClangCL, vcbuild x64 release openssl-no-asm): test/es-module/test-cjs-esm-warn.js passes 3/3 on the built binary.
  • Full suite (tools/test.py, 7281 tests): 56 failures, 55 of which fail identically on an unmodified nightly on the same machine (Windows symlink privilege, child_process shell, TLS CA, fs symlink/cp). The other, test-http-outgoing-end-cork, timed out under load and passes 10/10 in isolation on both binaries.

I'll follow up on review feedback myself.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. labels Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

@MikeMcC399

Copy link
Copy Markdown
Contributor

Not run locally: the test against a binary built from this branch (no ClangCL toolchain on my machine). I'll follow up on review feedback myself.

The Pull requests > Step 6: Test say:

Before submitting your changes in a pull request, always run the full Node.js test suite.

This is only possible if you have a local environment set up according to Building Node.js on supported platforms.

reconstructErrorStack() took the first stack frame as the caller, but
with a module.require tracing subscriber that frame is
TracingChannel.traceSync, so the arrow pointed at a nonexistent line
of the parent file. Pick the first frame that belongs to the parent.

Fixes: nodejs#55350
Signed-off-by: CodingRule <ioumih32@gmail.com>
@CodingRule
CodingRule force-pushed the fix/require-esm-error-annotation branch from 8dd31df to 60ad87b Compare October 22, 2026 17:52
@CodingRule

Copy link
Copy Markdown
Author

@MikeMcC399 thanks for pointing that out. I've since set up the Windows toolchain (VS 2022 + ClangCL) and run it locally on a build from this branch:

  • test/es-module/test-cjs-esm-warn.js: 3/3 pass, including the new case.
  • Full suite via tools/test.py (7281 tests): 56 failures. 55 of them fail identically on an unmodified nightly (v27.0.0-nightly20261020) on the same machine; they're Windows environment issues here (symlink privilege, child_process shell, TLS CA options, fs symlink/cp). The remaining one, test-http-outgoing-end-cork, was a request timeout under load and passes 10/10 in isolation on both binaries.

Updated the PR description accordingly.

@MikeMcC399

Copy link
Copy Markdown
Contributor

https://github.com/nodejs/node/blob/main/BUILDING.md#building-nodejs-2

Tip

On Windows, creating symlinks requires Developer Mode to be enabled or running the command as Administrator. Tests that rely on creating symlinks may fail with EPERM errors if symlink creation is not permitted.

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

Labels

module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong error annotation when commonjs requires an ES module

3 participants