Skip to content

Commit 35c501d

Browse files
committed
module: fix error reporting when commonjs requires an ES module
1 parent 5d4fee8 commit 35c501d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/internal/modules/cjs/loader.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1648,9 +1648,10 @@ function loadTS(module, filename) {
16481648
};
16491649

16501650
function reconstructErrorStack(err, parentPath, parentSource) {
1651-
const errLine = StringPrototypeSplit(
1651+
const stackFrames = StringPrototypeSplit(
16521652
StringPrototypeSlice(err.stack, StringPrototypeIndexOf(
1653-
err.stack, ' at ')), '\n', 1)[0];
1653+
err.stack, ' at ')), '\n');
1654+
const errLine = stackFrames[stackFrames.length - 1];
16541655
const { 1: line, 2: col } =
16551656
RegExpPrototypeExec(/(\d+):(\d+)\)/, errLine) || [];
16561657
if (line && col) {

0 commit comments

Comments
 (0)