Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
e027b6c2
Unverified
Commit
e027b6c2
authored
Feb 27, 2026
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Feb 27, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow Node.js' experimental inspector flags in `next dev` and `next build` (#90603)
parent
c0a661ee
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
129 additions
and
27 deletions
+129
-27
next-dev.ts
packages/next/src/cli/next-dev.ts
+5
-1
worker.ts
packages/next/src/lib/worker.ts
+5
-1
utils.test.ts
packages/next/src/server/lib/utils.test.ts
+27
-3
utils.ts
packages/next/src/server/lib/utils.ts
+55
-22
layout.tsx
test/e2e/node-cli-args/app/layout.tsx
+14
-0
page.tsx
test/e2e/node-cli-args/app/page.tsx
+4
-0
node-cli-args.test.ts
test/e2e/node-cli-args/node-cli-args.test.ts
+19
-0
No files found.
packages/next/src/cli/next-dev.ts
View file @
e027b6c2
...
@@ -323,8 +323,12 @@ const nextDev = async (
...
@@ -323,8 +323,12 @@ const nextDev = async (
nodeOptions
.
inspect
=
formatDebugAddress
(
address
)
nodeOptions
.
inspect
=
formatDebugAddress
(
address
)
}
}
const
{
nodeOptions
:
formattedNodeOptions
,
execArgv
}
=
formatNodeOptions
(
nodeOptions
)
child
=
fork
(
startServerPath
,
{
child
=
fork
(
startServerPath
,
{
stdio
:
'inherit'
,
stdio
:
'inherit'
,
execArgv
,
env
:
{
env
:
{
...
defaultEnv
,
...
defaultEnv
,
...(
isTurbopack
?
{
TURBOPACK
:
process
.
env
.
TURBOPACK
}
:
undefined
),
...(
isTurbopack
?
{
TURBOPACK
:
process
.
env
.
TURBOPACK
}
:
undefined
),
...
@@ -336,7 +340,7 @@ const nextDev = async (
...
@@ -336,7 +340,7 @@ const nextDev = async (
NODE_EXTRA_CA_CERTS
:
startServerOptions
.
selfSignedCertificate
NODE_EXTRA_CA_CERTS
:
startServerOptions
.
selfSignedCertificate
?
startServerOptions
.
selfSignedCertificate
.
rootCA
?
startServerOptions
.
selfSignedCertificate
.
rootCA
:
defaultEnv
.
NODE_EXTRA_CA_CERTS
,
:
defaultEnv
.
NODE_EXTRA_CA_CERTS
,
NODE_OPTIONS
:
format
NodeOptions
(
nodeOptions
)
,
NODE_OPTIONS
:
format
tedNodeOptions
,
// There is a node.js bug on MacOS which causes closing file watchers to be really slow.
// There is a node.js bug on MacOS which causes closing file watchers to be really slow.
// This limits the number of watchers to mitigate the issue.
// This limits the number of watchers to mitigate the issue.
// https://github.com/nodejs/node/issues/29949
// https://github.com/nodejs/node/issues/29949
...
...
packages/next/src/lib/worker.ts
View file @
e027b6c2
...
@@ -119,12 +119,15 @@ export class Worker {
...
@@ -119,12 +119,15 @@ export class Worker {
delete
nodeOptions
[
'max_old_space_size'
]
delete
nodeOptions
[
'max_old_space_size'
]
}
}
const
{
nodeOptions
:
formattedNodeOptions
,
execArgv
}
=
formatNodeOptions
(
nodeOptions
)
const
createWorker
=
()
=>
{
const
createWorker
=
()
=>
{
const
workerEnv
:
NodeJS
.
ProcessEnv
=
{
const
workerEnv
:
NodeJS
.
ProcessEnv
=
{
...
process
.
env
,
...
process
.
env
,
...((
farmOptions
.
forkOptions
?.
env
||
{})
as
any
),
...((
farmOptions
.
forkOptions
?.
env
||
{})
as
any
),
IS_NEXT_WORKER
:
'true'
,
IS_NEXT_WORKER
:
'true'
,
NODE_OPTIONS
:
format
NodeOptions
(
nodeOptions
)
,
NODE_OPTIONS
:
format
tedNodeOptions
,
}
}
if
(
workerEnv
.
FORCE_COLOR
===
undefined
)
{
if
(
workerEnv
.
FORCE_COLOR
===
undefined
)
{
...
@@ -148,6 +151,7 @@ export class Worker {
...
@@ -148,6 +151,7 @@ export class Worker {
...
farmOptions
,
...
farmOptions
,
forkOptions
:
{
forkOptions
:
{
...
farmOptions
.
forkOptions
,
...
farmOptions
.
forkOptions
,
execArgv
:
[...
execArgv
,
...(
farmOptions
.
forkOptions
?.
execArgv
||
[])],
env
:
workerEnv
,
env
:
workerEnv
,
},
},
maxRetries
:
0
,
maxRetries
:
0
,
...
...
packages/next/src/server/lib/utils.test.ts
View file @
e027b6c2
...
@@ -48,9 +48,33 @@ describe('formatNodeOptions', () => {
...
@@ -48,9 +48,33 @@ describe('formatNodeOptions', () => {
normal
:
'1234'
,
normal
:
'1234'
,
})
})
expect
(
result
).
toBe
(
expect
(
result
).
toEqual
({
'--spaces="thing with spaces" --spacesAndQuotes="thing with
\\
"spaces
\\
"" --normal=1234'
execArgv
:
[],
)
nodeOptions
:
'--spaces="thing with spaces" --spacesAndQuotes="thing with
\\
"spaces
\\
"" --normal=1234'
,
})
expect
(
result
.
execArgv
).
toEqual
([])
})
it
(
'separates exec-argv-only options from NODE_OPTIONS'
,
()
=>
{
const
result
=
formatNodeOptions
({
'enable-source-maps'
:
true
,
'experimental-network-inspection'
:
true
,
'experimental-storage-inspection'
:
true
,
'experimental-worker-inspection'
:
true
,
'experimental-inspector-network-resource'
:
true
,
'max-old-space-size'
:
'4096'
,
})
expect
(
result
).
toEqual
({
nodeOptions
:
'--enable-source-maps --max-old-space-size=4096'
,
execArgv
:
[
'--experimental-network-inspection'
,
'--experimental-storage-inspection'
,
'--experimental-worker-inspection'
,
'--experimental-inspector-network-resource'
,
],
})
})
})
})
})
...
...
packages/next/src/server/lib/utils.ts
View file @
e027b6c2
...
@@ -165,36 +165,69 @@ export const getParsedDebugAddress = (
...
@@ -165,36 +165,69 @@ export const getParsedDebugAddress = (
return
{
host
:
undefined
,
port
:
parseInt
(
address
,
10
)
}
return
{
host
:
undefined
,
port
:
parseInt
(
address
,
10
)
}
}
}
/**
* Node.js CLI flags that are not allowed in NODE_OPTIONS and must be
* passed as direct CLI arguments via execArgv.
* This set is the difference between all Node.js CLI flags and the ones **not**
* allowed in NODE_OPTIONS, as listed in the Node.js documentation:
* https://nodejs.org/api/cli.html#node_optionsoptions
*
* It is not exhaustive since not all options make sense for Next.js (e.g. --test)
*/
const
EXEC_ARGV_ONLY_OPTIONS
=
new
Set
([
'experimental-network-inspection'
,
'experimental-storage-inspection'
,
'experimental-worker-inspection'
,
'experimental-inspector-network-resource'
,
])
function
formatArg
(
key
:
string
,
value
:
string
|
boolean
|
undefined
):
string
|
null
{
if
(
value
===
true
)
{
return
`--
${
key
}
`
}
if
(
value
)
{
return
`--
${
key
}
=
${
// Values with spaces need to be quoted. We use JSON.stringify to
// also escape any nested quotes.
value
.
includes
(
' '
)
&&
!
value
.
startsWith
(
'"'
)
?
JSON
.
stringify
(
value
)
:
value
}
`
}
return
null
}
/**
/**
* Stringify the arguments to be used in a command line. It will ignore any
* Stringify the arguments to be used in a command line. It will ignore any
* argument that has a value of `undefined`.
* argument that has a value of `undefined`. Options that are not allowed in
* NODE_OPTIONS are returned separately as execArgv.
*
*
* @param args The arguments to be stringified.
* @param args The arguments to be stringified.
* @returns A
string with the arguments
.
* @returns A
n object with `nodeOptions` string and `execArgv` array
.
*/
*/
export
function
formatNodeOptions
(
export
function
formatNodeOptions
(
args
:
Record
<
string
,
string
|
boolean
|
undefined
>
args
:
Record
<
string
,
string
|
boolean
|
undefined
>
):
string
{
):
{
nodeOptions
:
string
;
execArgv
:
string
[]
}
{
return
Object
.
entries
(
args
)
const
nodeOptionsParts
:
string
[]
=
[]
.
map
(([
key
,
value
])
=>
{
const
execArgv
:
string
[]
=
[]
if
(
value
===
true
)
{
return
`--
${
key
}
`
}
if
(
value
)
{
for
(
const
[
key
,
value
]
of
Object
.
entries
(
args
))
{
return
`--
${
key
}
=
${
const
formatted
=
formatArg
(
key
,
value
)
// Values with spaces need to be quoted. We use JSON.stringify to
if
(
formatted
===
null
)
continue
// also escape any nested quotes.
value
.
includes
(
' '
)
&&
!
value
.
startsWith
(
'"'
)
if
(
EXEC_ARGV_ONLY_OPTIONS
.
has
(
key
))
{
?
JSON
.
stringify
(
value
)
execArgv
.
push
(
formatted
)
:
value
}
else
{
}
`
nodeOptionsParts
.
push
(
formatted
)
}
}
}
return
null
return
{
nodeOptions
:
nodeOptionsParts
.
join
(
' '
),
execArgv
}
})
.
filter
((
arg
)
=>
arg
!==
null
)
.
join
(
' '
)
}
}
export
function
getParsedNodeOptions
():
Record
<
export
function
getParsedNodeOptions
():
Record
<
...
@@ -237,7 +270,7 @@ export function getFormattedNodeOptionsWithoutInspect() {
...
@@ -237,7 +270,7 @@ export function getFormattedNodeOptionsWithoutInspect() {
const
args
=
getParsedNodeOptionsWithoutInspect
()
const
args
=
getParsedNodeOptionsWithoutInspect
()
if
(
Object
.
keys
(
args
).
length
===
0
)
return
''
if
(
Object
.
keys
(
args
).
length
===
0
)
return
''
return
formatNodeOptions
(
args
)
return
formatNodeOptions
(
args
)
.
nodeOptions
}
}
/**
/**
...
...
test/e2e/node-cli-args/app/layout.tsx
0 → 100644
View file @
e027b6c2
import
*
as
React
from
'react'
export
default
function
RootLayout
({
children
,
}:
{
children
:
React
.
ReactNode
})
{
return
(
<
html
>
<
head
/>
<
body
>
{
children
}
</
body
>
</
html
>
)
}
test/e2e/node-cli-args/app/page.tsx
0 → 100644
View file @
e027b6c2
export
default
async
function
Page
()
{
await
fetch
(
'https://next-data-api-endpoint.vercel.app/api/random'
)
return
<
p
>
hello world
</
p
>
}
test/e2e/node-cli-args/node-cli-args.test.ts
0 → 100644
View file @
e027b6c2
import
{
nextTestSetup
}
from
'e2e-utils'
describe
(
'node-cli-args'
,
()
=>
{
const
{
next
}
=
nextTestSetup
({
files
:
__dirname
,
startCommand
:
`node --experimental-network-inspection ./node_modules/next/dist/bin/next
${
process
.
env
.
NEXT_TEST_MODE
===
'dev'
?
'dev'
:
'start'
}
`
,
skipDeployment
:
true
,
skipStart
:
true
,
})
it
(
'should start server with --experimental-network-inspection'
,
async
()
=>
{
if
(
process
.
version
.
startsWith
(
'v20'
))
{
// --experimental-network-inspection is not supported in Node 20.
await
expect
(
next
.
start
()).
rejects
.
toThrow
()
}
else
{
await
next
.
start
()
}
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment