【发布时间】:2022-10-25 17:10:41
【问题描述】:
我一直在阅读 Node.js 原生支持源映射。但是我不明白在向控制台打印错误时如何使用源映射。
我试过用--enable-source-maps 运行节点,也试过source-map-support 包。但无济于事。控制台中的输出只显示了转译后的 js 代码,而不是 ts 源代码。
我究竟做错了什么?
源代码:
// main.ts
const someError = new Error()
console.error(someError.stack)
控制台输出(来自 VS Code):
/home/birger/.nvm/versions/node/v16.16.0/bin/node ./build/main.js -r source-map-support/register
Error
at Object.<anonymous> (/home/birger/someproject/build/main.js:8:19)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
这是我的 tsconfig.json:
// tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"sourceMap": true,
"strict": true,
"skipLibCheck": true,
"outDir": "build",
"noImplicitAny": false,
}
}
【问题讨论】:
标签: node.js typescript source-maps