question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VS Code debugger broken (Exception: Inspector is already activated)

See original GitHub issue

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:

https://github.com/gatsbyjs/gatsby/blob/7e83aced6b5c9fc421fd8f3b67b77269a6b59f09/packages/gatsby/src/commands/develop-process.ts#L67

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 setting debug.node.useV3 to true; either one should cause VS Code to use the new Node.js debugger
  • Moving "--inspect-brk" to runtimeArgs 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:closed
  • Created 3 years ago
  • Comments:22 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
connor4312commented, Dec 15, 2020

It was a simple fix, so I put in a PR.

2reactions
connor4312commented, Sep 3, 2020

Hi, I build the JS debugger.

Two things:

  • @aaronadamsCA passing --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.
  • Throwing the error is new behavior as of https://github.com/nodejs/node/commit/dd5f209213a2b75bb386b44c296a059fc10dfb02. You can detect that the inspector is already open by seeing if inspector.url() !== undefined (eg)
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found