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

lib: fix inspector links for stack traces #35725

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: inspector links for stack traces
When the chrome inspector (chrome://inspect) display stack traces, it
makes the filename clickable, and developer can easily locate the
relevant source with a single click. This only works when filenames are
valid URLs. The CJS loader seems to compile sources with absolute path
instead of URL, breaking the inspector functionality. This is especially
apparent when node_modules contain "at" symbol (@). The loader already
presents module to the inspector using file URL, the same URL should be
used for compiling the source.
  • Loading branch information
Dragiyski committed Jan 19, 2021
commit da6626b5f59ab1a01c296d7801e86cf87bc0187e
6 changes: 5 additions & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1020,10 +1020,14 @@ function wrapSafe(filename, content, cjsModuleInstance) {
});
}
let compiled;
let filenameUrl = filename;
try {
filenameUrl = normalizeReferrerURL(filename);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise, if we can instead test for filename patterns that would make normalizeReferrerURL throw, it might be better than a catch all try/catch.

} catch {}
try {
compiled = compileFunction(
content,
filename,
filenameUrl,
0,
0,
undefined,
Expand Down