ts-node
ts-node copied to clipboard
Incorrect sourcemapping in files with newlines in Node 20.1
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?:
I can reproduce the same error with the current main git ts-node
Is this due to the breaking change in node 20, where they moved esm loaders to a different thread?
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.
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