我已经检查了以下答案:
How to debug async/await in visual studio code?
然而,这两个都没有解决我的问题。
我希望能够使用Node.js v7.4.0从VSCode调试本机异步/等待,而不是可怕的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"
]
}
launch.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:
发布于 2019-05-25 16:23:33
终于想明白了。使用Typescript和Jest。分享我所拥有的,希望能帮助到一些人。节点11,VScode 1.34.0
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["-i", "${relativeFile}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"sourceMaps": true,
"smartStep": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
}
]
}
tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": ".",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"inlineSources": true,
"sourceRoot": "/",
"declaration": false,
"module": "es2015",
"esModuleInterop": true,
"resolveJsonModule": true,
"stripInternal": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2017",
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom", "esnext.asynciterable"],
"types": ["chrome", "node", "jest"]
}
}
但是,这只在某些情况下有效。如果你能把你的应用编译成JS ES2017就行了。angular无法编译到该es版本。它只适用于某些测试文件。非常令人沮丧的是,angular编译器不能输出es2017。而且它不会在很多年后还会出现。
https://stackoverflow.com/questions/41644827
复制相似问题