I want to debug js file that includes async/await in visual studio code,but it reminds me that vscode doesn't support it. What can I do to make vscode support async/await?
Double-clicking an active or awaiting task shows the async call stack in the Call Stack window. To understand which thread is running a specific task, you can swap between the Parallel Threads and Parallel Tasks windows. You can do this by right-clicking and selecting Go To Thread in the context menu.
Debug asynchronous code Debugging asynchronous code is a challenge because the tasks are often scheduled in one thread and executed in another. Every thread has its own stacktrace, making it difficult to figure out what happened before the thread started.
To start debugging, select F5, or choose the Debug Target button in the Standard toolbar, or choose the Start Debugging button in the Debug toolbar, or choose Debug > Start Debugging from the menu bar. The app starts and the debugger runs to the line of code where you set the breakpoint.
In the last async debugging blog post, we explored several tools in Visual Studio to help you debug your async code. One of the tools we discussed was the Parallel Stacks window for Tasks (or Parallel Tasks), a tool that provides task and thread information while debugging.
The additions of the Task type, async, and await in .NET provide an extra layer of abstraction, which enable you to write responsive applications but also make it harder to navigate through and understand the status of each awaiting or active task while debugging.
Async code can be analyzed through a parallel task, parallel watch, parallel threads, or the tasks window. Use all these tools together to analyze async code thoroughly.
1) press ctrl+p in vscode and type ">launch", select "open launch.json" 2) after opening "launch.json", just add to configuration section : After these steps you can see your real async method after pressing F11 in debug mode. Show activity on this post.
As now, in 2019, latest VSCode supporting async/await debug, just would like to share solution to prevent vscode to "Step into" (by f11) into async/await method through the "async_hooks.js" and "inspector_async_hook.js" files during debug nodejs applications.
Howto :
1) press ctrl+p in vscode and type ">launch", select "open launch.json"
2) after opening "launch.json", just add to configuration section :
"skipFiles": [ "inspector_async_hook.js", "async_hooks.js" ]
or some more generic version :
"skipFiles": ["<node_internals>/**"]
So you final json should looks something like here:
{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Launch Program", "program": "${workspaceFolder}\\index.js", "skipFiles": ["<node_internals>/**"] } ] }
After these steps you can see your real async method after pressing F11 in debug mode.
Currently you can use async/await in Node.js 7 or latest using --harmony flag, you can configure your vscode debugger (launch.json) in the following way to run and debug async/await Nodejs 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 change the program by your startup script file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With