VS Code debugger broken (Exception: Inspector is already activated)
See original GitHub issueGatsby has recently stopped working with defined debugger launch configurations in Visual Studio Code.
I don’t know if this was due to a change in Gatsby or in VS Code and/or its extensions; I just know it worked at some point in the last couple of months, and now it doesn’t.
Steps to reproduce
Update: I can reproduce this issue in a starter repo using the exact launch configuration from the docs:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Gatsby develop",
"type": "node",
"request": "launch",
"protocol": "inspector",
"program": "${workspaceRoot}/node_modules/.bin/gatsby",
"autoAttachChildProcesses": true,
"args": ["develop", "--inspect-brk"],
"stopOnEntry": false,
"runtimeArgs": ["--nolazy"],
"sourceMaps": false
},
{
"name": "Gatsby build",
"type": "node",
"request": "launch",
"protocol": "inspector",
"program": "${workspaceRoot}/node_modules/.bin/gatsby",
"args": ["build"],
"stopOnEntry": false,
"runtimeArgs": ["--nolazy"],
"sourceMaps": false
}
]
}
This is the line throwing an unhandled exception:
This is the exception:
Exception has occurred: Error [ERR_INSPECTOR_ALREADY_ACTIVATED]: Inspector is already activated. Close it with inspector.close() before activating it again.
at Object.open (inspector.js:137:11)
Some things I’ve tried adjusting without success:
- Changing
"type": "node"
to"type": "pwa-node"
and/or settingdebug.node.useV3
totrue
; either one should cause VS Code to use the new Node.js debugger - Moving
"--inspect-brk"
toruntimeArgs
or removing it entirely
Workaround
Auto-attach is not affected. If I set VS Code setting debug.node.autoAttach
to true
and then run node --nolazy node_modules/.bin/gatsby develop --inspect-brk
in the terminal, the debugger attaches and Gatsby runs without exception.
Environment
System:
OS: Linux 4.19 Debian GNU/Linux 9 (stretch) 9 (stretch)
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Shell: 4.4.12 - /bin/bash
Binaries:
Node: 12.18.3 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/bin/yarn
npm: 6.14.6 - /usr/local/bin/npm
Languages:
Python: 2.7.13 - /usr/bin/python
npmPackages:
gatsby: ^2.24.52 => 2.24.52
gatsby-source-sanity: ^6.0.3 => 6.0.3
Issue Analytics
- State:
- Created 3 years ago
- Comments:22 (18 by maintainers)
Top Results From Across the Web
Debugging in Visual Studio Code
One of the great things in Visual Studio Code is debugging support. Set breakpoints, step-in, inspect variables and more.
Read more >VS-Code won't pause debugger on exception inside Promise
I do have both All Exceptions and Uncaught Exceptions ticked under breakpoints. I am using: Visual Studio Code 1.17.2. Node 8.8.1. Inspector ......
Read more >Debug Python code - Visual Studio (Windows) - Microsoft Learn
The basic debugging workflow involves settings breakpoints, stepping through code, inspecting values, and handling exceptions as described in ...
Read more >Debugging - vscode-docs
In addition to debugging a program, VS Code supports running the program. The Run action is triggered with kb(workbench.action.debug.run) and uses the currently...
Read more >Manual: Debug C# code in Unity
This is the recommended way to set up Visual Studio for Mac for debugging with Unity. If Visual Studio for Mac is already...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It was a simple fix, so I put in a PR.
Hi, I build the JS debugger.
Two things:
--inspect-brk
to Gatsby is probably unnecessary. We --require a ‘bootloader’ script via NODE_OPTIONS which sets up debugging before the process (i.e. Gatsby) gets activated. Omitted the argument will supposedly cause Gatsby to not try to enter debug mode again which should bypass the error.inspector.url() !== undefined
(eg)