Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEXT-1179] Chrome dev tools debugging #48767

Closed
1 task done
EmilioHerreraSoukup opened this issue Apr 24, 2023 · 7 comments · Fixed by #51467
Closed
1 task done

[NEXT-1179] Chrome dev tools debugging #48767

EmilioHerreraSoukup opened this issue Apr 24, 2023 · 7 comments · Fixed by #51467
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@EmilioHerreraSoukup
Copy link

EmilioHerreraSoukup commented Apr 24, 2023

Verify canary release

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

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.19.0
      npm: 8.19.3
      Yarn: N/A
      pnpm: 8.3.1
    Relevant packages:
      next: 13.3.1
      eslint-config-next: 13.3.1
      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

N/A

To Reproduce

Add a debugger line after running the app via "NODE_OPTIONS='--inspect' next dev

Describe the Bug

Happened after upgrading from next 12 to 13:

  • Chrome dev tools should stop execution in the debugger line. Now is not being detected, execution just continues.

Expected Behavior

Chrome dev tools should stop execution in the debugger line

Which browser are you using? (if relevant)

Chrome 112.0.5615.137

How are you deploying your application? (if relevant)

No response

NEXT-1179

@EmilioHerreraSoukup EmilioHerreraSoukup added the bug Issue was opened via the bug report template. label Apr 24, 2023
@shuding
Copy link
Member

shuding commented May 1, 2023

In latest version of Next.js we run multiple Node.js processes, so the --inspect arg only got passed to the main process. CC @ijjk shall we always forward that (and set new ports for workers with a output message)?

@pauledwards241
Copy link

I've just tried this in version 13.4.0 and it still does not allow server side debugging.

Prior to version 13.3.x, it (mostly) worked by following the workaround posted by @icyJoseph

It can be reproduced quite quickly using the TypeScript Next.js example

@jonnywyatt
Copy link

Just wondering if this is being prioritised? It's quite a major impediment to developing production apps with Next.js 13

@juhahe
Copy link

juhahe commented May 13, 2023

Ran into this issue as well. As mentioned above, the issue is that the debug server is started on the wrong node process. As a workaround, you can start debug servers on any of the running processes started by next by sending them USR1 signal (https://nodejs.org/en/docs/guides/debugging-getting-started#enable-inspector).

I observed that next starts three processes like node /my/path/to/node_modules/next/dist/compiled/jest-worker/processChild.js. I haven't gone through the source code to understand what those processes do and don't know if this works at all in general, but so far on my system (macOS) the middle process when ordered by IDs has been the server process I've wanted to debug when I've set breakpoints in Route Handlers. So I've been using this hacky workaround in my package.json scripts run with bash:

    "debug": "kill -USR1 \"$(pgrep -f \"node ${PWD}/.*node_modules/next/.*/jest-worker\" | head -2 | tail -1)\"",
    "debug-cli": "npm run debug && node inspect 127.0.0.1:9229",

When the next server is up and running, npm run debug sends USR1 signal to the "middle" jest-worker node process which then starts the debug server and you can connect to it with an inspector client like Chrome DevTools. Alternatively, npm run debug-cli starts the debug server and also connects the nodejs built-in CLI debugger to it.

@timneutkens timneutkens added the linear: next Confirmed issue that is tracked by the Next.js team. label May 17, 2023
@timneutkens timneutkens changed the title Chrome dev tools debugging [NEXT-1179] Chrome dev tools debugging May 17, 2023
@juhahe
Copy link

juhahe commented May 22, 2023

It appears a fix is being worked on here #48019

@pauledwards241
Copy link

It appears a fix is being worked on here #48019

I notice this fix was merged as part of v13.4.4, but I'm still unable to debug. Has anyone else had any luck with the latest release?

@kodiakhq kodiakhq bot closed this as completed in #51467 Jun 25, 2023
kodiakhq bot pushed a commit that referenced this issue Jun 25, 2023
## Fixing a bug

Fixes #50489
Fixes #48767
Fixes #45697

## What?
When running `NODE_OPTIONS='--inspect' next dev`
Then go to `http://localhost:3000/`
Will display error message `WebSockets request was expected` like the following screenshot
![image](https://github.com/vercel/next.js/assets/14261588/d2f3e520-7cce-40db-be69-99980804cc51)

Also the debug port for app and page still not follow by user input
When `NODE_OPTIONS='--inspect=8000' next dev` the app debug port still `54151`
![image](https://github.com/vercel/next.js/assets/14261588/e3d25c0e-9d00-4767-94d6-d954776912b2)


## Why?
#50248 added a function `getFreePort()` and it used on debug port and HTTP server port
So conflict happen between debug and HTTP port
Then show up error `WebSockets request was expected`

Here are some references about this error:
https://stackoverflow.com/questions/49766500/websockets-request-was-expected-error-when-using-inspect-brk-option


## How?
1. `getFreePort()` should only use on HTTP server
2. Added `getDebugPort()` for read the port from user input
3. Assign port to each worker
4. Add accurate info log for each debug port, e.g.: `proxy`,`router`,`app`,`page`

When `NODE_OPTIONS='--inspect' next dev` 
![image](https://github.com/vercel/next.js/assets/14261588/2260fdff-13fe-435a-9812-984315c0ea2e)

When `NODE_OPTIONS='--inspect=8000' next dev` 
![image](https://github.com/vercel/next.js/assets/14261588/de6e2f2d-9216-481f-b6db-7c5132e97b6f)

Also fix VSCode debugger
It is worth noting that
We can't hit the breakpoint on the first execution
because the file does not exist there yet or was not compiled
In most cases, the breakpoint can only be triggered normally during the second execution
![image](https://github.com/vercel/next.js/assets/14261588/dccded50-46c5-4b6d-beb7-ff0e5324327a)


Closes NEXT-1179
Closes NEXT-517



Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants