ts-node调试TS时Step Into无法进入RxJS原始ts文件如何解决
问题根因
调试无法进入RxJS原始TS文件由两个配置问题导致:
launch.json中resolveSourceMapLocations规则直接排除了所有node_modules路径下的sourcemap解析,调试器无法识别RxJS编译产物和原始TS文件的映射关系,只会加载编译后的JS代码- ts-node默认会忽略所有
node_modules下的文件转译,直接加载包导出的CommonJS编译产物
修复方案
1. 修改调试配置launch.json
调整sourcemap解析规则,仅排除RxJS之外的第三方包sourcemap,同时开启智能步过跳过无映射的编译代码,跳过Node.js内部模块:
{ "version": "0.2.0", "configurations": [ { "name": "Launch TS", "type": "pwa-node", "request": "launch", "runtimeArgs": ["-r", "ts-node/register"], "cwd": "${workspaceRoot}", "resolveSourceMapLocations": [ "${workspaceFolder}/**", "!**/node_modules/!(rxjs)/**" ], "smartStep": true, "skipFiles": [ "<node_internals>/**" ], "args": ["${file}"] } ] }
2. 调整tsconfig.json配置
新增ts-node专属配置,取消对RxJS包的忽略规则,让ts-node可以正确关联其源码映射:
{ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "sourceMap": true, "strict": true, "moduleResolution": "node", "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true }, "ts-node": { "ignore": ["node_modules/(?!rxjs)"] } }
3. 校验本地RxJS文件完整性
正常通过包管理器安装的RxJS,会在node_modules/rxjs/src目录下存放完整原始TS源码,dist/cjs目录下的编译JS文件也自带对应sourcemap文件,无需额外安装依赖。
验证结果
保存配置后重启调试会话,在原断点位置点击Step Into,会直接跳转至node_modules/rxjs/src/internal/operators/map.ts原始TS文件,可正常断点调试RxJS operator实现逻辑。
内容的提问来源于stack exchange,提问作者Archsx
相关产品推荐
相关产品推荐

