Skip to content

Incorrect sourcemapping in files with newlines in Node 20.1 #2006

@richardsimko

Description

@richardsimko

Search Terms

sourcemap, source map, 20

Expected Behavior

Source maps map the correct line even if the file has a newline (Which gets removed by tsc)

Actual Behavior

On Node 20.1 the mapping excludes the newlines.

Steps to reproduce the problem

Run the repro repo yarn run test on Node 20.1 and Node 19 and observe the difference in stack locations for the thrown error.

Node 20.1:

Error: Error
    at file:///Users/richard/git/tsnodesourcemaptest/index.ts:7:7
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)

Node 19:

Error: Error
    at file:///Users/richard/git/tsnodesourcemaptest/index.ts:12:7
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)

There is also a test-js script included which will compile and run the output JS file with --enable-source-maps. In this case the source map is correct on both versions.

Minimal reproduction

https://github.com/richardsimko/ts-node-sourcemap-bug

Specifications

  • ts-node version: 10.9.1
  • node version: 20.1
  • TypeScript version: 5.0.4
  • tsconfig.json, if you're using one:
{
  "compilerOptions": {
    "outDir": "./build",
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "node",
    "sourceMap": true
  },
  "ts-node": {
    "files": true,
    "swc": true
  },
  "include": ["**/*.ts"]
}
  • package.json:
{
  "name": "tsnodesourcemaptest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "test": "node --loader ts-node/esm index.ts",
    "test-js": "tsc && node --enable-source-maps build/index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@swc/core": "^1.3.56",
    "ts-node": "^10.9.1",
    "typescript": "^5.0.4"
  }
}
  • Operating system and version: macOS 13.3
  • If Windows, are you using WSL or WSL2?:

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