gatsby: VS Code debugger broken (Exception: Inspector is already activated)
Gatsby 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.useV3totrue; either one should cause VS Code to use the new Node.js debugger - Moving
"--inspect-brk"toruntimeArgsor 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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (18 by maintainers)
Commits related to this issue
- chore(docs): Fix and simplify VS Code launch.json (#26782) * Removes `--inspect-brk` flag to address #26708 * Sets `"type": "pwa-node"` to opt into the new Node.js debugger * Removes `"protocol"`, ... — committed to gatsbyjs/gatsby by aaronadamsCA 4 years ago
- fix(gatsby): Do not activate inspect if already active (#26708) — committed to connor4312/gatsby by connor4312 4 years ago
- fix(gatsby): Do not activate inspect if already active (#26708) — committed to connor4312/gatsby by connor4312 4 years ago
It was a simple fix, so I put in a PR.
Hi, I build the JS debugger.
Two things:
--inspect-brkto 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)I think this is still valid
Amazing, thank you @connor4312, removing
--inspect-brkdoes indeed bypass the error.@wardpeet, at this point this might just be a documentation thing? Compared to the current docs it seems this is now the better recommendation for
launch.json:In addition to removing
--inspect-brk, other changes include:"type": "pwa-node"to opt into the new Node.js debugger; it ships with VS Code stable, works well, and will soon be the only option, so IMO it’s already the right choice"protocol"because it does nothing with"request": "launch""autoAttachChildProcesses"and"stopOnEntry"because there’s no need to restate defaults"sourceMaps": false, I don’t see any documented/ticketed reason to recommend this"console": "integratedTerminal"to be able to see Gatsby console outputRe-opened, i’ll have a look