fix: preserve repeated --require/--import flags when forking workers (#96651)
Repeated --require/--import flags in NODE_OPTIONS are corrupted when
Next.js reparses and reformats the options for forked workers.
## What changed
- Declare `require` and `import` as repeatable options in
`parseNodeArgs` so `parseArgs` accumulates every occurrence into an
array instead of keeping only the last value (equals form) or joining
the space form into one bogus specifier.
- Emit one flag per array element in `formatArg`/round-trip.
- Widened `NodeOptions` and `getParsedDebugAddress` to accept
`string[]`.
## Why
Two preloads in `NODE_OPTIONS` (e.g. an APM agent plus an env loader)
silently lose one in forked workers (`--require=a --require=b`), or
crash the build (`--require a --require b`, joining paths into a single
MODULE_NOT_FOUND). Node itself runs every occurrence; the round-trip
through Next must preserve them.
Fixes #96582
## Validation
- Unit tests in `packages/next/src/server/lib/utils.test.ts` cover both
spellings, repeated `--import`, quoted values, and array formatting (22
passing).
- `pnpm --filter=next types` clean.
Signed-off-by:
Anuj Bolewar <bolewara@gmail.com>
Showing
Please
register
or
sign in
to comment