Closed
Description
Version
- v18.13.0
- v20.11.1
Platform
Microsoft Windows NT 10.0.19044.0 x64
Subsystem
No response
What steps will reproduce the bug?
Details for how I generated hi.mjs
Create a source file, hi_src.ts
:
// @ts-ignore Cannot find module node:path
import { sep } from 'node:path'
throw new Error(sep)
npm i -g esbuild
esbuild hi_src.ts --outfile=hi.mjs --sourcemap=inline --format=esm
(Same results when you pass --sourcemap=linked
)
- Create a file called
hi.mjs
:
import { sep } from "node:path";
throw new Error(sep);
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiaGlfc3JjLnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyIvLyBAdHMtaWdub3JlIENhbm5vdCBmaW5kIG1vZHVsZSBub2RlOnBhdGhcbmltcG9ydCB7IHNlcCB9IGZyb20gJ25vZGU6cGF0aCdcbnRocm93IG5ldyBFcnJvcihzZXApXG4iXSwKICAibWFwcGluZ3MiOiAiQUFDQSxTQUFTLFdBQVc7QUFDcEIsTUFBTSxJQUFJLE1BQU0sR0FBRzsiLAogICJuYW1lcyI6IFtdCn0K
- Run
cat hi.mjs | node --enable-source-maps --input-type=module
- See the error stack trace says line 2, but I'd expect line 3.
How often does it reproduce? Is there a required condition?
always
What is the expected behavior?
I'd expect to see the error on line 3, since that's where the error is in the source file.
What do you see instead?
I see the error on line 2:
C:\Users\Joseph\Code\test>cat hi.mjs | node --enable-source-maps --input-type=module
file:///C:/Users/Joseph/Code/test/[eval1]:2
throw new Error(sep);
^
Error: \
at file:///C:/Users/Joseph/Code/test/[eval1]:2:7
Node.js v18.13.0
Additional information
This file works as expected if you pass the filename to node (the normal way of using node):
C:\Users\Joseph\Code\test>node --enable-source-maps hi.mjs
C:\Users\Joseph\Code\test\hi_src.ts:3
throw new Error(sep)
^
Error: \
at <anonymous> (C:\Users\Joseph\Code\test\hi_src.ts:3:7)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
Node.js v18.13.0
Not specific to ESM modules. I'm getting the wrong lines in stack traces for Common JS too.
Activity
ArtskydJ commentedon Dec 19, 2024
Was still broken in 20.16.0, but fixed in 20.17.0! 🎉
I'm guessing either #53860 or #51977 fixed it, but I really don't know.