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

"NODE_OPTIONS='--inspect' next dev" won't work correctly, debugging server-side not possiable #47561

Closed
1 task done
Dkogan90 opened this issue Mar 27, 2023 · 6 comments · Fixed by #48019
Closed
1 task done
Labels
bug Issue was opened via the bug report template. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@Dkogan90
Copy link

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.3.0: Thu Jan  5 20:49:43 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T8103
    Binaries:
      Node: 17.9.1
      npm: 8.11.0
      Yarn: 1.22.10
      pnpm: N/A
    Relevant packages:
      next: 13.2.5-canary.19
      eslint-config-next: 13.2.4
      react: 18.2.0
      react-dom: 18.2.0

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

Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue

https://github.com/Dkogan90/next-bug

To Reproduce

Starting next: yarn run dev
try to debugging pages/api/hello.ts with chrome node inspector

Describe the Bug

Inspector is already running.
Unable to debug server-side code.

$ NODE_OPTIONS='--inspect' next dev
Debugger listening on ws://127.0.0.1:9229/9a701303-c48a-4785-9ee0-8bea5a0e4cff
For help, see: https://nodejs.org/en/docs/inspector
warn  - the --inspect option was detected, the Next.js server should be inspected at port 9230.
Debugger listening on ws://127.0.0.1:9230/33c493f4-afba-4ac8-b7af-7c18e6e56b11
For help, see: https://nodejs.org/en/docs/inspector
ready - started server on 0.0.0.0:3000, url: http://localhost:3000
Starting inspector on 127.0.0.1:9229 failed: address already in use

Expected Behavior

Able to debug server side code with the node.js inspector via chrome

Which browser are you using? (if relevant)

Chrome

How are you deploying your application? (if relevant)

not relevant

@Dkogan90 Dkogan90 added the bug Issue was opened via the bug report template. label Mar 27, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Mar 27, 2023
@icyJoseph
Copy link
Contributor

Hi @Dkogan90

I've managed to get this to work, but it was really weird.

To me it stood out:

warn  - the --inspect option was detected, the Next.js server should be inspected at port 9230.

In spite of the line that points to 9229:

Debugger listening on ws://127.0.0.1:9229/9a701303-c48a-4785-9ee0-8bea5a0e4cff

So in the chrome://inspect UI I clicked on Configure, and added localhost:9230 to the debug list:

Screenshot 2023-03-29 at 13 46 45

And then I was able to debug:

Screenshot 2023-03-29 at 13 51 38

It also works with api/hello.ts:

Screenshot 2023-03-29 at 13 53 23

And it also works with middleware:

Screenshot 2023-03-29 at 13 54 26

To me the weird thing is that it'd bump from 9229 to 9230, and I wonder if it is related to this from the docs:

Be aware that running NODE_OPTIONS='--inspect' npm run dev or NODE_OPTIONS='--inspect' yarn dev won't work. This would try to start multiple debuggers on the same port: one for the npm/yarn process and one for Next.js. You would then get an error like Starting inspector on 127.0.0.1:9229 failed: address already in use in your console.

Even if we do as they instruct, that seems to happen, could it be that there's some binary under the hood, that triggers this issue anyway?

@edorgeville
Copy link

Duplicate of #47083

@wowczarczyk
Copy link

I was successful debugging in VS Code using the following launch configuration:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}/node_modules/next/dist/bin/next",
            "runtimeArgs": [
                "--inspect"
            ]
        }
    ]
}

@Cow258
Copy link
Contributor

Cow258 commented May 16, 2023

I was successful debugging in VS Code using the following launch configuration:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${workspaceFolder}/node_modules/next/dist/bin/next",
            "runtimeArgs": [
                "--inspect"
            ]
        }
    ]
}

Which version of Next.js are you using?
Will it break when you added breakpoint into API or Page routes?

@wowczarczyk
Copy link

wowczarczyk commented May 16, 2023 via email

ijjk added a commit that referenced this issue May 23, 2023
## Bug

This fix closes #47083 issue 
This fix closes #47561 issue
This fix closes #48376 issue
**Invalid repetition PRs:** #47671 (this PR changing expired code)
(This issue still exist on
[v13.4.3-canary.1](https://github.com/vercel/next.js/releases/tag/v13.4.3-canary.1)

- [x] Related issues linked using `fixes #number`

### What?
When running `NODE_OPTIONS='--inspect' next dev`, 
the render server didn't start with `--inspect`. 
In some cases, 
the `--inspect` flag will be passed when `__NEXT_DISABLE_MEMORY_WATCHER`
was set.

### Why?
Since #47208 revamped some startup processes, the `NODE_OPTIONS`
environment parameter is not passed down to the render server worker.

### How?
Just add back the original startup process.


![image](https://user-images.githubusercontent.com/14261588/230398898-791e6909-6f4c-493b-937d-058a7b788849.png)


link NEXT-1176

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
hydRAnger pushed a commit to hydRAnger/next.js that referenced this issue Jun 12, 2023
## Bug

This fix closes vercel#47083 issue 
This fix closes vercel#47561 issue
This fix closes vercel#48376 issue
**Invalid repetition PRs:** vercel#47671 (this PR changing expired code)
(This issue still exist on
[v13.4.3-canary.1](https://github.com/vercel/next.js/releases/tag/v13.4.3-canary.1)

- [x] Related issues linked using `fixes #number`

### What?
When running `NODE_OPTIONS='--inspect' next dev`, 
the render server didn't start with `--inspect`. 
In some cases, 
the `--inspect` flag will be passed when `__NEXT_DISABLE_MEMORY_WATCHER`
was set.

### Why?
Since vercel#47208 revamped some startup processes, the `NODE_OPTIONS`
environment parameter is not passed down to the render server worker.

### How?
Just add back the original startup process.


![image](https://user-images.githubusercontent.com/14261588/230398898-791e6909-6f4c-493b-937d-058a7b788849.png)


link NEXT-1176

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
@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 Jun 23, 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. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants