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

#12578 breaks command react-router dev --any-param #12606

Open
Master-Hash opened this issue Dec 20, 2024 · 6 comments
Open

#12578 breaks command react-router dev --any-param #12606

Master-Hash opened this issue Dec 20, 2024 · 6 comments
Labels

Comments

@Master-Hash
Copy link

I'm using React Router as a...

framework

Reproduction

  1. Define script in packages.json: "dev": "react-router dev --host",
  2. run pnpm run dev

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (16) x64 AMD Ryzen 7 6800U with Radeon Graphics
    Memory: 2.19 GB / 15.24 GB
  Binaries:
    Node: 23.4.0 - C:\Program Files\nodejs\node.EXE
    pnpm: 9.15.1 - C:\Program Files\nodejs\pnpm.CMD
    bun: 1.1.29 - C:\Program Files\WinGet\Links\bun.EXE
  Browsers: {}
  npmPackages:
    @react-router/dev: ^7.1.0 => 7.1.0
    @react-router/fs-routes: ^7.1.0 => 7.1.0
    @react-router/node: ^7.1.0 => 7.1.0
    @react-router/serve: ^7.1.0 => 7.1.0
    react-router: ^7.1.0 => 7.1.0
    vite: ^6.0.5 => 6.0.5

Used Package Manager

pnpm

Expected Behavior

Just works

Actual Behavior

> react-router dev --host

C:\Users\hash\Desktop\xxxx\node_modules\.pnpm\arg@5.0.2\node_modules\arg\index.js:132
                                                throw new ArgError(
                                                ^

ArgError: unknown or unexpected option: --host
    at arg (C:\Users\hash\Desktop\taup\node_modules\.pnpm\arg@5.0.2\node_modules\arg\index.js:132:13)
    at Object.<anonymous> (C:\Users\hash\Desktop\taup\node_modules\.pnpm\@react-router+dev@7.1.0_@react-router+serve@7.1.0_react-router@7.1.0_react-dom@19.0.0_react@1_aa57s26fwl7ukaaplgz4hwj76m\node_modules\@react-router\dev\bin.js:8:12)   
    at Module._compile (node:internal/modules/cjs/loader:1566:14)
    at Object..js (node:internal/modules/cjs/loader:1718:10)
    at Module.load (node:internal/modules/cjs/loader:1305:32)
    at Function._load (node:internal/modules/cjs/loader:1119:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:151:5)
    at node:internal/main/run_main_module:33:47 {
  code: 'ARG_UNKNOWN_OPTION'
}
@PhilDL
Copy link
Contributor

PhilDL commented Dec 21, 2024

#12578 is indeed the issue, you can fixed it locally by patching the @react-router/dev package with the following changes.

diff --git a/bin.js b/bin.js
index 88866010646f42058bd8daf29896fb6be55d4eb7..0373bf96f7c42f5460dc2e9fea394e9a7e947e06 100755
--- a/bin.js
+++ b/bin.js
@@ -5,7 +5,7 @@ let arg = require("arg");
 // default `NODE_ENV` so React loads the proper version in it's CJS entry script.
 // We have to do this before importing `run.ts` since that is what imports
 // `react` (indirectly via `react-router`)
-let args = arg({}, { argv: process.argv.slice(2) });
+let args = arg({}, { argv: process.argv.slice(2), stopAtPositional: true });
 if (args._[0] === "dev") {
   process.env.NODE_ENV = process.env.NODE_ENV ?? "development";
 } else {

Adding stopPositional: true to the arg function (that was called with no positional args {}) will make it bypass optional positional args often used like build --sourcemapClient --sourcemapServer. So the function will not crash anymore.

@patsaas
Copy link

patsaas commented Dec 21, 2024

P1. It's not just react-router dev but react-router with any parameter.

@jesse996
Copy link

same, react router dev --mode dev not work

@timdorr
Copy link
Member

timdorr commented Dec 23, 2024

I've released 7.1.1-pre.0 on npm with just that fix. I don't know if I have access to finish the full release here (I'm not a Shopify employee), so I'm leaving it as a prerelease for now.

@IsaacCloos
Copy link

IsaacCloos commented Dec 24, 2024

I believe this issue should remain open. I'm still getting the following error on windows 11

npm ls -g
+-- @react-router/[email protected]
`-- [email protected]

 npx react-router -h
...\AppData\Roaming\npm\node_modules\@react-router\dev\node_modules\arg\index.js:132
                                                throw new ArgError(
                                                ^

ArgError: unknown or unexpected option: -h
 ... {
  code: 'ARG_UNKNOWN_OPTION'
}

Node.js v22.12.0

extra info:

npx react-router -h works on version 7.0.2. the same menu (I think) shows up if you do npx react-router dev -h on 7.1.1, which I believe the root command is an alias of.

@Master-Hash Master-Hash reopened this Dec 24, 2024
@PhilDL
Copy link
Contributor

PhilDL commented Dec 24, 2024

This specific issue with the dev option is fixed and should remained closed, but the other one #12627 about the command with no option (dev | build | etc) should probably be reopened yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants