Skip to content

Line numbers in stack traces are wrong in Node v20 #2053

Open

Description

@gthb

Search Terms

line numbers

Note that there is #1495, closed almost two years ago, long before Node v20 came out. I opened a new issue because (a) root causes are likely different even if the manifestation is similar, and (b) the way to reproduce is likely different as well, and (c) I can't reopen that old one anyway :) but the problem is clearly present today.

Expected Behavior

I expect line numbers in stack traces thrown from TypeScript code to match the actual line numbers in the file, when running under Node v20, as they do when running under Node v18 and v19.

Actual Behavior

When running under Node v20, line numbers in stack traces are wrong, appearing to be from the transpiled version of the module.

Steps to reproduce the problem

Run a TypeScript module in which an error is thrown. Observe that the line numbers in the stack trace of that error are incorrect when running in Node v20, but are correct when running in Node v18 or v19.

Minimal reproduction

TypeStrong/ts-node-repros#34

Specifications

  • ts-node version: v10.9.1
  • node version: v20.5.1
  • TypeScript version: v5.2.2
  • tsconfig.json, if you're using one:
{}
  • package.json:
{
  "type": "module",
  "dependencies": {
    "ts-node": "latest",
    "typescript": "latest"
  }
}
  • Operating system and version: macOS 13.5.1 (22G90)

Activity

  1. SoftwareAndOutsourcing commented on Nov 10, 2023

    @SoftwareAndOutsourcing

    I can reproduce this issue.

    With the same code, stack trace line numbers are wrong with Node.Js 20. By just switching to Node.js 18, I get the correct ones.

  2. uriva commented on Nov 28, 2023

    @uriva

    same on node 21

  3. gthb commented on Dec 12, 2023

    @gthb
    Author

    This problem occurs in Node v18.19.0. It does not occur in Node v18.18.2.

    So, seems likely that the cause is one of the changes reported as backported from v20 in https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V18.md#2023-11-29-version-18190-hydrogen-lts-targos

    As a superficial guess, my money is on feat(esm): leverage loaders when resolving subsequent loaders #43772 as a likely cause. :)

  4. gthb commented on Dec 12, 2023

    @gthb
    Author

    Updated TypeStrong/ts-node-repros#34 accordingly, so it now uses v18.19.0 and exhibits the problem.

  5. SoftwareAndOutsourcing commented on Dec 12, 2023

    @SoftwareAndOutsourcing

    I replaced ts-node with tsx, and now I get the correct line numbers with node 20.

  6. sparecycles commented on Jan 4, 2024

    @sparecycles

    seeing the same issue with ts-morph: a workaround seems to be adding inline source maps and running node with --enable-source-maps.

    {
          ...
          sourceMap: true,
          inlineSourceMap: true,
          mapRoot: 'file:///'
    }

    and

    project.createSourceFile(/* full '/...' */ sourcepath, source)
  7. apazzolini commented on Jan 9, 2024

    @apazzolini

    seeing the same issue with ts-morph: a workaround seems to be adding inline source maps and running node with --enable-source-maps.

    I can confirm adding --enable-source-maps fixes this issue for me in Node 20. I did not have to enable inline source maps or change my ts-node configuration in any other way.

  8. dandv commented on Jun 19, 2024

    @dandv

    node --loader=ts-node/esm --enable-source-maps myscript.ts fixes this issue for me in Node 18.19.0 as well. I didn't have to change anything in tsconfig.json.

  9. thesmart commented on Apr 26, 2025

    @thesmart

    I'd like to bump this issue. Seems like a foot gun for most users?

  10. PsySecCorp commented on Aug 7, 2025

    @PsySecCorp

    Can confirm that the line numbers are off by ~-40 in v20.16.0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions