Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Open
stinaq opened this issue Mar 27, 2025 · 5 comments
Open

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

stinaq opened this issue Mar 27, 2025 · 5 comments
Labels
Script (next/script) Related to Next.js Script Optimization.

Comments

@stinaq
Copy link

stinaq commented Mar 27, 2025

Link to the code that reproduces this issue

https://github.com/stinaq/newrelic-node-examples/tree/main/nextjs/nextjs-app-router

To Reproduce

  1. npm install to get correct dependencies
  2. npm run dev to start dev server

running this runs the command

NODE_OPTIONS='-r dotenv/config --loader newrelic/esm-loader.mjs -r newrelic' next dev

it's starting the dev server according to Newrelic setup.

I filed an issue over at their repo, but they are saying the issue comes from the next CLI.

Specifically this line

Current vs. Expected behavior

When running this command, starting the server fails with the following error message:

--r= is not allowed in NODE_OPTIONS

note that the command run does not include --r.

Expected behavior is that the server can run

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:24 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6030
  Available memory (MB): 18432
  Available CPU cores: 12
Binaries:
  Node: 20.19.0
  npm: 10.8.2
  Yarn: N/A
  pnpm: 9.5.0
Relevant Packages:
  next: 15.2.4 // Latest available version is detected (15.2.4).
  eslint-config-next: 14.1.4
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.8.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Script (next/script)

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

I filed an issue over at their repo, but they are saying the issue comes from the next CLI.

Specifically this line

@bas-pxr
Copy link

bas-pxr commented Mar 27, 2025

Hello @stinaq. We ran into this before when implementing newrelic. We found that replacing -r with the long form --require worked for us.

@bizob2828
Copy link

bizob2828 commented Mar 27, 2025

Yes that is a solution but -r is a valid node option and this change seems to have broken that. The Node.js CLI options doc specifies many with -

@stinaq
Copy link
Author

stinaq commented Mar 27, 2025

yes @bas-pxr that is true, but as @bizob2828 says, it should still be valid to write -r

@icyJoseph
Copy link
Contributor

icyJoseph commented Apr 1, 2025

This is interesting, I think a fix like this is needed, just a proto-type:

// parseNodeArgs
  const rawNames = tokens.filter(token => token.kind === 'option')

  const valuesWithRawNames = Object.entries(values).reduce((acc, [key, value]) => {
    const rawName = rawNames.find(token => token.name === key)?.rawName;
    if (rawName) {
      acc[rawName] = value;
    } else {
      acc[key] = value; // maybe not needed? 
    }
    return acc;
  }, {})

  return valuesWithRawNames

This would be done within, parseNodeArgs, to preserve the rawName of the flag used, since these could be -, or -- kind of flags. Then formatNodeOptions would be just:

// formatNodeOptions
    .map(([key, value]) => {
      if (value === true) {
        return key
      }

      if (value) {
        return `${key}=${

Since the key, is the rawName used by the invoker.

I'll try to make PR with these changes... hopefully it works well

@martinjlowm
Copy link

Contributed #71759 a long time ago to fix this. No response.

I was just trying to upgrade Next.js again, facing this same issue. For us it's because we use Yarn PnP and another level of runtime effects (Node runtime GraphQL support and SWC transpilation of TypeScript)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Script (next/script) Related to Next.js Script Optimization.
Projects
None yet
Development

No branches or pull requests

5 participants