Cannot read properties of undefined (reading 'length')
Bug Description
$ npx react-doctor@latest --verbose --diff
Something went wrong. Please check the error below for more details.
If the problem persists, please open an issue at https://github.com/millionco/react-doctor/issues.
Cannot read properties of undefined (reading 'length')
Environment
- react-doctor version:
latest(0.2.4) - Node.js version:
v26.0.0
Got this too
fixing - thank you
Reproducing this as well on 0.2.4. Adding root cause analysis below in case it's helpful.
Workaround
Use --diff=<base> (inline value) instead of --diff with no argument — this avoids the buggy code path.
[!NOTE] The analysis below is AI generated.
Root Cause Analysis
The crash is in stripUnknownCliFlags → stripUnknownFlags, specifically in shouldConsumeNextArgument (cli.js:14780).
The bug: When --diff is the last CLI argument (no value after it), shouldConsumeNextArgument incorrectly returns true:
// Line 14779 — required values: correctly guards against undefined
if (flagSpec.longOptionsWithRequiredValues.has(optionName)) return nextArgument !== void 0;
// Line 14780 — optional values: missing the same guard!
return flagSpec.longOptionsWithOptionalValues.has(optionName) && !isFlagLike(nextArgument ?? "");
When nextArgument is undefined (nothing after --diff), the ?? coalesces it to "", isFlagLike("") returns false, so the function returns true — "consume the next argument." stripUnknownFlags then pushes userArguments[outOfBounds] (undefined) into the sanitized args array. Commander's parseOptions subsequently calls maybeOption(undefined), which crashes on undefined.length.
Suggested fix (line 14780):
return flagSpec.longOptionsWithOptionalValues.has(optionName)
&& nextArgument !== undefined
&& !isFlagLike(nextArgument);
pushed on latest - please let me know if you are still experiencing this issue!
It now works normally for npx react-doctor@latest --verbose --diff.
@rayhanadev
going to close this issue since it seems it was fixed in the latest release 🫡