next.js: [NEXT-517] Breakpoint not getting hit in VSCode with Next.js debugger config

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 16.14.2
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.1.7-canary.7
      eslint-config-next: 13.1.6
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue

https://github.com/InfiniteLearner/debug_error_next_reproduction

To Reproduce

!!! You should be using node v 16.14.2 !!!

(Because of other constraints I can not update my node version so this is not an option)

Create a new next.js app npx create-next-app@latest Use every default options

Add a new config for debugging in vsCode (.vscode/launch.json):

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Next.js: debug server-side",
        "type": "node-terminal",
        "request": "launch",
        "command": "npm run dev"
      },
      {
        "name": "Next.js: debug client-side",
        "type": "chrome",
        "request": "launch",
        "url": "http://localhost:3000"
      },
      {
        "name": "Next.js: debug full stack",
        "type": "node-terminal",
        "request": "launch",
        "command": "npm run dev",
        "serverReadyAction": {
          "pattern": "started server on .+, url: (https?://.+)",
          "uriFormat": "%s",
          "action": "debugWithChrome"
        }
      }
    ]
  }

Create a new async function in index.tsx and call it (with an onClick for example):

async function greeting(){
    console.log("Hello");
    console.log("Goodbye");
  }

...

<p onClick={greeting}></p>
...

Add a new breakpoint in the function. 2023-02-08_11h49_26

Run in debug mode (either server-side, client-side or fullstack).

Describe the Bug

On click of the element, the logs will be displayed without being stop. The breakpoints are not getting hit.

2023-02-08_11h50_08

It should be noted that breakpoints on the returned component are working fine but none in functions. So if you had a breakpoint on your div (or any other component) it will stop.

Expected Behavior

The breakpoints should get hit and the logs not be displayed.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-517

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 6
  • Comments: 24 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Just wondering how is this not a huge problem for tons of people or why isn’t it getting much attention from authors?

I’m having the same problem.

My debugger attaches, it just doesn’t stop at a breakpoint

  • Operating System:
    • Platform: OSX
    • Arch: x64
    • Version: Ventura
  • Binaries: -Node: v18.14.0
  • Relevant packages:
    • next: 13.1.6
    • eslint-config-next: 13.1.6
    • react: 18.2.0
    • react-dom: 18.2.0

I can’t get to pause VS Code or just Chrome

I should also note that I’m using TypeScript

I’m also experiencing this issue. Tried

  1. modifying next-server.js -no luck
  2. tweaking the launch.json - no luck

VSCode version. 1.78 OS: M1 Mac Ventura 13.0

Just wondering how is this not a huge problem for tons of people or why isn’t it getting much attention from authors?

This is really baffling, but the reason is that most devs don’t know how to use debuggers and rely mostly on logs which is soo inefficient. It is a lost battle at this point.

A thing that doesn’t seem to be mentioned is that I’m able to stop the execution in a server function by adding a debugger statement. Waiting for the first execution to pass then waiting for the 2nd one to attach doesn’t seem to work for me.

The issue with the debugger (and I assume breakpoints) is that it stops in a file that has the same contents and name as the actual function file, but it’s not the same file (?!).

Note that the file with the debugger doesn’t show Git diffs nor breadcrumbs.

Screenshot 2023-07-06 at 11 33 07 Screenshot 2023-07-06 at 11 33 01

I’m using Turborepo so that might add other issues into the mix. I think it would be worth having a sample Next.js repo with clear instructions on how to debug the code.

Just set the Javascript: Auto attach filter to Always in your workspace or user settings.

Then you can start the dev server with npm run dev in a terminal.

image

Up+. I got the same issue. Can not hit breakpoints