How to debug async / await in Visual Studio code?

I want to debug a js file that includes async / await in the visual studio code, but this reminds me that vscode does not support it. What can I do to make vscode support async / await?

+7
javascript async-await visual-studio-code
source share
3 answers

You can currently use async / await in Node.js 7 or later using the --harmony flag, you can configure your vscode debugger (launch.json) as follows to start and debug Nodejs async / wait code.

{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Node 7 Async/Await", "program": "${workspaceRoot}/main.js", "cwd": "${workspaceRoot}", "runtimeArgs": [ "--harmony", "--no-deprecation" ] }, { "type": "node", "request": "attach", "name": "Attach to Process", "port": 5858 } ] } 

You must modify the program using the boot script file.

+4
source share

I had serious performance issues when VS Code debugging a Node project with TypeScript , so I found that changing protocol=='inspector' and targeting es2017 allowed es2017 to quickly and reliably debug. Here is the configuration I used ...

launch.json

 { "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch Program", "program": "${workspaceRoot}/lib/main.js", "protocol": "inspector", "runtimeArgs": [ "--harmony", "--no-deprecation" ], "outFiles": [ "${workspaceRoot}/lib/**/*.js" ], "skipFiles": [ "${workspaceRoot}/node_modules/**/*.js" ], "smartStep": true } ] } 

tsconfig.json

 { "compilerOptions": { "target": "es2017", "module": "commonjs", "declaration": true, "sourceMap": true, "outDir": "lib", "lib": [ "dom", "es2017" ], "suppressImplicitAnyIndexErrors": true, "allowSyntheticDefaultImports": true }, "compileOnSave": true, "exclude": [ "node_modules" ], "include": [ "src" ] } 
0
source share

You can use the Node.js --inspect to debug code in Chrome. Similar:

 # node --inspect app/app.js 

And open Chrome: chrome://inspect . It's so cool.
You can specify in this document .

0
source share

All Articles