Skip to content

Commit

Permalink
fix(debugging): do not pass NODE_OPTIONS='--inspect' to subprocesses
Browse files Browse the repository at this point in the history
fixes #11030
  • Loading branch information
vvo committed Mar 19, 2020
1 parent 087a887 commit c7ac253
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/next/server/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '')
}
9 changes: 9 additions & 0 deletions packages/next/server/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import ErrorDebug from './error-debug'
import HotReloader from './hot-reloader'
import { findPageFile } from './lib/find-page-file'
import Worker from 'jest-worker'
import { getNodeOptionsWithoutInspect } from './lib/utils'

if (typeof React.Suspense === 'undefined') {
throw new Error(
Expand Down Expand Up @@ -88,11 +89,19 @@ export default class DevServer extends Server {
forkOptions: {
env: {
...process.env,
<<<<<<< HEAD
// discard process.env.NODE_OPTIONS --inspect flag otherwise two debuggers are started in inspect
// mode when users will try to debug their Next.js application with NODE_OPTIONS='--inspect' next dev
NODE_OPTIONS: process.env.NODE_OPTIONS
? process.env.NODE_OPTIONS.replace(/--inspect(-brk)?(=\S+)? ?/, '')
: '',
=======
// 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(),
>>>>>>> fix(debugging): do not pass NODE_OPTIONS='--inspect' to subprocesses
},
},
}
Expand Down
10 changes: 10 additions & 0 deletions test/integration/cli/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(`http://localhost:${port}`))
})

test('-p', async () => {
const port = await findPort()
const output = await runNextCommandDev([dir, '-p', port], true)
Expand Down

0 comments on commit c7ac253

Please sign in to comment.