From 9f08ef8daf28bd4e19894c617617f88ad9d1bdff Mon Sep 17 00:00:00 2001 From: Seiry Yu <4397354+seiry@users.noreply.github.com> Date: Fri, 10 Mar 2023 06:12:54 +0800 Subject: [PATCH] fix: Add NODE_OPTIONS for debugging in next-dev (#46757) ## Bug fix #46948 - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [x] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md) Co-authored-by: Seiry Yu --- packages/next/src/cli/next-dev.ts | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/next/src/cli/next-dev.ts b/packages/next/src/cli/next-dev.ts index 37cf40fe76e56..6ed36e19cc260 100644 --- a/packages/next/src/cli/next-dev.ts +++ b/packages/next/src/cli/next-dev.ts @@ -477,22 +477,27 @@ If you cannot make the changes above, but still want to try out\nNext.js v13 wit let config: NextConfig let childProcess: ChildProcess | null = null - const isDebugging = process.execArgv.some((localArg) => - localArg.startsWith('--inspect') - ) + const isDebugging = + process.execArgv.some((localArg) => localArg.startsWith('--inspect')) || + process.env.NODE_OPTIONS?.match?.(/--inspect(=\S+)?( |$)/) - const isDebuggingWithBrk = process.execArgv.some((localArg) => - localArg.startsWith('--inspect-brk') - ) + const isDebuggingWithBrk = + process.execArgv.some((localArg) => + localArg.startsWith('--inspect-brk') + ) || process.env.NODE_OPTIONS?.match?.(/--inspect-brk(=\S+)?( |$)/) const debugPort = (() => { - const debugPortStr = process.execArgv - .find( - (localArg) => - localArg.startsWith('--inspect') || - localArg.startsWith('--inspect-brk') - ) - ?.split('=')[1] + const debugPortStr = + process.execArgv + .find( + (localArg) => + localArg.startsWith('--inspect') || + localArg.startsWith('--inspect-brk') + ) + ?.split('=')[1] ?? + process.env.NODE_OPTIONS?.match?.( + /--inspect(-brk)?(=(\S+))?( |$)/ + )?.[3] return debugPortStr ? parseInt(debugPortStr, 10) : 9229 })()