gpt4 book ai didi

node.js - 调试 session 期间 typescript 未定义的常量

转载 作者:行者123 更新时间:2023-12-03 12:14:39 24 4
gpt4 key购买 nike

我有以下带有 Typescript 的 Node.js project运行得很好。但是,在调试 session 期间,我注意到从另一个 Typescript 文件导出的常量总是 undefined :

enter image description here

我有点怀疑这是由于空 names生成的源映射中的数组:

{
"version": 3,
"file": "main.js",
"sourceRoot": "",
"sources": [
"../src/main.ts"
],
"names": [], // <---- empty
"mappings": ...details omitted...
}

有没有办法从 Typescript 编译器或其他解决方案中生成正确的源映射来解决这个调试问题?以下是我的 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 的 Node runner 运行的:

enter image description here

旁注 :这个问题在我调试一个通过 ng serve 运行的 Angular 应用程序时没有发生。 .不确定是什么 ng serve与标准不同 tsc .

最佳答案

是的,空的"names": []在源映射中是问题 - tsc将您命名的导入编译为 category_1.ANIMAL_TYPE ,并且没有名称映射,因此在调试器中变量未定义......在 VSCode 中调试时您将面临同样的问题,例如:

enter image description here

您可以查看 category_1对象以查看值:

enter image description here

我不知道有什么方法可以改变 tsc行为:(

关于node.js - 调试 session 期间 typescript 未定义的常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59864978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com