我检查了以下答案:
Nodejs 7 的异步等待 https://stackoverflow.com/questions/41347260/async-await-with-nodejs-7
如何在 Visual Studio 代码中调试异步/等待? https://stackoverflow.com/questions/37771097/how-to-debug-async-await-in-visual-studio-code
然而两者都没有解决我的问题。
我希望能够使用 Node.js v7.4.0 从 VSCode 调试本机 Async/Await,而无需使用可怕的 Typescript 转译版本。我能够让 Typescript 输出正确的代码,即没有 __awaiter 等。但是,一旦我尝试调试代码,所有转译的状态机代码都会出现!?所以我可以调试代码,它只是不是我想要调试的代码。是否有办法防止调试的代码具有转译的状态机代码?
这是我的配置文件:
tsconfig.json
{
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"noImplicitAny": false,
"sourceMap": true,
"outDir": "lib",
"noUnusedParameters": false,
"noUnusedLocals": false,
"skipLibCheck": true
//"importHelpers": true
},
"exclude": [
"node_modules"
]
}
启动.json
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/jest-cli/bin/jest.js",
"stopOnEntry": false,
"cwd": "${workspaceRoot}",
//"preLaunchTask": "tsc",
"runtimeExecutable": null,
"args": [
"--runInBand"
],
"runtimeArgs": [
"--harmony-async-await",
"--no-deprecation"
],
"env": {
"NODE_ENV": "development"
},
"console": "integratedTerminal",
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/{lib}/**/*.js"
],
"skipFiles": [
"node_modules/**/*.js",
"lib/**/*.js"
]
}
为了进一步说明我的意思,下面是输出的 javascript 中的一段代码:
let handler = subscription.messageSubscription.handler;
debugger;
await handler(message.message, context);
然而,调试后它看起来像这样:
case 4:
handler = subscription.messageSubscription.handler;
debugger;
return [4 /*yield*/, handler(message.message, context)];
case 5: