Skip to content

fix: correct parseNodeArgs and formatNodeOptions processing of NODE_OPTIONS#89968

Draft
runderworld wants to merge 1 commit intovercel:canaryfrom
runderworld:fix/node-options-v16
Draft

fix: correct parseNodeArgs and formatNodeOptions processing of NODE_OPTIONS#89968
runderworld wants to merge 1 commit intovercel:canaryfrom
runderworld:fix/node-options-v16

Conversation

@runderworld
Copy link
Copy Markdown

What?

Fixes #77550 — Port of PR #71759 to v16.x (canary).

--r= is an invalid value if passed to NODE_OPTIONS, which was the outcome from -r file.js because all options were forcefully prefixed with -- and repeated short options (e.g. multiple -r) were deduplicated.

Why?

parseNodeArgs and formatNodeOptions did not account for:

  • Short options that may have values (not simply booleans)
  • Repeated options (e.g. -r a.js -r b.js)
  • Preserving the original dash prefix (- vs --)

How?

  • parseNodeArgs now uses token.rawName to preserve - vs -- prefixes and stores values as arrays to support repeated options.
  • Introduced a NodeOptions class wrapping the parsed result with get/set/delete/has/clone/raw helpers, replacing direct property access on a plain object. This keeps callers clean while supporting the richer internal representation.
  • formatNodeOptions handles array values and uses the correct separator (= for --long options, space for -short options).
  • Updated callers in next-dev.ts and worker.ts to use NodeOptions methods.
  • Added tests for repeated -r/--require options (short and long forms), short option formatting, repeated option formatting, and boolean options.

Files changed

  • packages/next/src/server/lib/utils.ts
  • packages/next/src/server/lib/utils.test.ts
  • packages/next/src/cli/next-dev.ts
  • packages/next/src/lib/worker.ts

Credits

Based on the original work by @martinjlowm in #71759 (v15.x), adapted for the v16.x codebase.

@nextjs-bot
Copy link
Copy Markdown
Collaborator

Allow CI Workflow Run

  • approve CI run for commit: 01e0839

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@nextjs-bot
Copy link
Copy Markdown
Collaborator

nextjs-bot commented Feb 13, 2026

Allow CI Workflow Run

  • approve CI run for commit: 8604ded

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@runderworld runderworld force-pushed the fix/node-options-v16 branch 2 times, most recently from 6a30d07 to d74d4aa Compare February 13, 2026 20:32
@runderworld runderworld force-pushed the fix/node-options-v16 branch 2 times, most recently from 724c36e to c4781fd Compare February 21, 2026 01:10
…PTIONS

Fixes vercel#77550 — Port of PR vercel#71759 to v16.x (canary).

The core issue: parseNodeArgs used node:util parseArgs which strips dash
prefixes and deduplicates keys. When NODE_OPTIONS contains repeated short
options like '-r file1.js -r file2.js', the old code lost values and
formatNodeOptions forced '--' prefix on everything (turning '-r' into
'--r=', which is invalid in NODE_OPTIONS).

Changes:
- parseNodeArgs now uses token.rawName to preserve '-' vs '--' prefixes
  and stores values as arrays to support repeated options
- Introduced NodeOptions class wrapping the parsed result with get/set/
  delete/has/clone/raw helpers for clean caller interaction
- formatNodeOptions updated to handle array values and use the correct
  separator ('=' for long options, ' ' for short options)
- Updated callers in next-dev.ts and worker.ts to use NodeOptions methods
- Added tests for repeated -r/--require options (short and long forms),
  short option formatting, repeated option formatting, and boolean options
- Applied Graphite bot suggestion: filter(Boolean) before join in inner
  map to avoid extra spaces from null values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nextjs dev server can't be started with additional -r node parameters

2 participants