Unverified Commit fa5da6d2 authored by Vincent Voyer's avatar Vincent Voyer Committed by GitHub

Remove passing of NODE_OPTIONS='--inspect' to subprocesses (#11041)

* fix(debugging): do not pass NODE_OPTIONS='--inspect' to subprocesses

fixes #11030

* fix(debugger): use a regex to remove bad NODE_OPTIONS flags
Co-authored-by: 's avatarAlec Larson <alec.stanford.larson@gmail.com>
parent f9cd7c58
......@@ -8,3 +8,8 @@ export function printAndExit(message: string, code = 1) {
process.exit(code)
}
export function getNodeOptionsWithoutInspect() {
const NODE_INSPECT_RE = /--inspect(-brk)?(=\S+)? ?/
return (process.env.NODE_OPTIONS || '').replace(NODE_INSPECT_RE, '')
}
......@@ -31,6 +31,7 @@ import { Telemetry } from '../telemetry/storage'
import ErrorDebug from './error-debug'
import HotReloader from './hot-reloader'
import { findPageFile } from './lib/find-page-file'
import { getNodeOptionsWithoutInspect } from './lib/utils'
if (typeof React.Suspense === 'undefined') {
throw new Error(
......@@ -87,6 +88,16 @@ export default class DevServer extends Server {
{
maxRetries: 0,
numWorkers: this.nextConfig.experimental.cpus,
forkOptions: {
env: {
...process.env,
// discard --inspect/--inspect-brk flags from process.env.NODE_OPTIONS. Otherwise multiple Node.js debuggers
// would be started if user launch Next.js in debugging mode. The number of debuggers is linked to
// the number of workers Next.js tries to launch. The only worker users are interested in debugging
// is the main Next.js one
NODE_OPTIONS: getNodeOptionsWithoutInspect(),
},
},
}
) as Worker & {
loadStaticPaths: typeof import('./static-paths-worker').loadStaticPaths
......
......@@ -88,6 +88,16 @@ describe('CLI Usage', () => {
expect(output).toMatch(new RegExp(`http://localhost:${port}`))
})
test("NODE_OPTIONS='--inspect'", async () => {
// this test checks that --inspect works by launching a single debugger for the main Next.js process,
// not for its subprocesses
const port = await findPort()
const output = await runNextCommandDev([dir, '--port', port], true, {
env: { NODE_OPTIONS: '--inspect' },
})
expect(output).toMatch(new RegExp(`ready on http://localhost:${port}`))
})
test('-p', async () => {
const port = await findPort()
const output = await runNextCommandDev([dir, '-p', port], true)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment