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

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

Merged
merged 3 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, '')
}
11 changes: 11 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 { 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(
Expand Down Expand Up @@ -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
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(`ready on http://localhost:${port}`))
})

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