调试会话期间打字稿未定义常量
Typescript undefined constant during debugging session
我有以下 Node.js 和 Typescript project 运行 绝对没问题。但是,在调试期间,我注意到从另一个 Typescript 文件导出的常量总是 undefined
:
我有点怀疑这是由于生成的 source maps:
中的空 names
数组造成的
{
"version": 3,
"file": "main.js",
"sourceRoot": "",
"sources": [
"../src/main.ts"
],
"names": [], // <---- empty
"mappings": ...details omitted...
}
有没有办法从 Typescript 编译器或其他解决方案生成正确的 source map 来解决这个调试问题?以下是我的 tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"target": "es2017",
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"sourceMap": true,
"allowJs": true,
"outDir": "dist",
"baseUrl": ".",
"typeRoots": [
"./node_modules/@types"
],
"types": [
"node"
],
"paths": {
"*": [
"node_modules/*"
]
}
},
"include": [
"src/**/*"
]
}
我正在使用 Typescript 3.7.5。
项目只是 运行 通过 Webstorm 的节点 运行ner:
旁注:当我调试 运行 到 ng serve
的 Angular 应用程序时,没有发生此问题。不确定 ng serve
与标准 tsc
.
有何不同
是的,源映射中的空 "names": []
是问题所在 - tsc
将您的命名导入编译为 category_1.ANIMAL_TYPE
,并且没有名称映射,因此变量在调试器中未定义... 在 VSCode 中调试时,您将面临同样的问题,例如:
您可以检查 category_1
对象以查看值:
我不知道有什么方法可以改变 tsc
行为:(
我有以下 Node.js 和 Typescript project 运行 绝对没问题。但是,在调试期间,我注意到从另一个 Typescript 文件导出的常量总是 undefined
:
我有点怀疑这是由于生成的 source maps:
中的空names
数组造成的
{
"version": 3,
"file": "main.js",
"sourceRoot": "",
"sources": [
"../src/main.ts"
],
"names": [], // <---- empty
"mappings": ...details omitted...
}
有没有办法从 Typescript 编译器或其他解决方案生成正确的 source map 来解决这个调试问题?以下是我的 tsconfig.json
:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"target": "es2017",
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"sourceMap": true,
"allowJs": true,
"outDir": "dist",
"baseUrl": ".",
"typeRoots": [
"./node_modules/@types"
],
"types": [
"node"
],
"paths": {
"*": [
"node_modules/*"
]
}
},
"include": [
"src/**/*"
]
}
我正在使用 Typescript 3.7.5。
项目只是 运行 通过 Webstorm 的节点 运行ner:
旁注:当我调试 运行 到 ng serve
的 Angular 应用程序时,没有发生此问题。不确定 ng serve
与标准 tsc
.
是的,源映射中的空 "names": []
是问题所在 - tsc
将您的命名导入编译为 category_1.ANIMAL_TYPE
,并且没有名称映射,因此变量在调试器中未定义... 在 VSCode 中调试时,您将面临同样的问题,例如:
您可以检查 category_1
对象以查看值:
我不知道有什么方法可以改变 tsc
行为:(