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

Incorrect sourcemapping in files with newlines in Node 20.1 #2006

Open
richardsimko opened this issue May 4, 2023 · 4 comments
Open

Incorrect sourcemapping in files with newlines in Node 20.1 #2006

richardsimko opened this issue May 4, 2023 · 4 comments

Comments

@richardsimko
Copy link

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?:
@insilications
Copy link

I can reproduce the same error with the current main git ts-node

@cspotcode
Copy link
Collaborator

Is this due to the breaking change in node 20, where they moved esm loaders to a different thread?

@insilications
Copy link

Is this due to the breaking change in node 20, where they moved esm loaders to a different thread?

Probably. Seems like 20 support is problematic right now. More than >80 tests failing in the main branch with 20.

@thetutlage
Copy link
Contributor

Using --enable-source-maps works fine with loader hooks too. The following command on the same repo points to correct line.

node --enable-source-maps --loader ts-node/esm index.ts

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

4 participants