首页 > 解决方案 > 如何在 VS 代码上调试包含 Class 的打字稿文件?

问题描述

在 VS Code 中,我试图调试(在 Node.Js 环境中)一个包含类的打字稿文件。虽然我已经能够在没有类的情况下调试 .ts 文件。

样本.ts

 class A {
    value: string;
    constructor() {
        this.value = "some_value";
    }
    print() {
        console.log(this.value)
    }
 }

 let v = new A();
 v.print();  

尝试调试“sample.ts”时显示以下错误

Process exited with code 1
Uncaught f:\TS\sample.ts:2
    value: string;
    

SyntaxError: Unexpected identifier
No debugger available, can not send 'variables'

SyntaxError: Unexpected identifier
    at wrapSafe (internal/modules/cjs/loader.js:1047:16)
    at Module._compile (internal/modules/cjs/loader.js:1097:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
    at internal/main/run_main_module.js:18:47

标签: typescriptdebuggingvisual-studio-codevscode-debugger

解决方案


推荐阅读