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

--enable-source-maps does not work with stdin #46454

Closed
ArtskydJ opened this issue Feb 1, 2023 · 1 comment
Closed

--enable-source-maps does not work with stdin #46454

ArtskydJ opened this issue Feb 1, 2023 · 1 comment

Comments

@ArtskydJ
Copy link

ArtskydJ commented Feb 1, 2023

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)


  1. Create a file called hi.mjs:
import { sep } from "node:path";
throw new Error(sep);
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiaGlfc3JjLnRzIl0sCiAgInNvdXJjZXNDb250ZW50IjogWyIvLyBAdHMtaWdub3JlIENhbm5vdCBmaW5kIG1vZHVsZSBub2RlOnBhdGhcbmltcG9ydCB7IHNlcCB9IGZyb20gJ25vZGU6cGF0aCdcbnRocm93IG5ldyBFcnJvcihzZXApXG4iXSwKICAibWFwcGluZ3MiOiAiQUFDQSxTQUFTLFdBQVc7QUFDcEIsTUFBTSxJQUFJLE1BQU0sR0FBRzsiLAogICJuYW1lcyI6IFtdCn0K
  1. Run cat hi.mjs | node --enable-source-maps --input-type=module
  2. 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.

Source map visualization

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.

@ArtskydJ
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant