itwanger/toBeBetterJavaer · error · Error
Unknown option: ${arg}
Error message
Unknown option: ${arg} What it means
Thrown by the argument parser of scripts/sync-sidebar.js when a token matches none of the recognized options (--help/-h, --write, --check, --verbose, --sidebar, --route, --dir, --fallback and their =value forms). Unlike the convert script, this parser has no positional-argument branch, so EVERY unmatched token throws — including non-dash tokens.
Source
Thrown at scripts/sync-sidebar.js:81
} else if (arg.startsWith("--sidebar=")) {
options.sidebar = path.resolve(ROOT_DIR, arg.slice("--sidebar=".length));
} else if (arg === "--route") {
options.route = normalizeRoute(requireValue(argv, index));
index += 1;
} else if (arg.startsWith("--route=")) {
options.route = normalizeRoute(arg.slice("--route=".length));
} else if (arg === "--dir") {
options.dir = requireValue(argv, index);
index += 1;
} else if (arg.startsWith("--dir=")) {
options.dir = arg.slice("--dir=".length);
} else if (arg === "--fallback") {
options.fallbackGroup = requireValue(argv, index);
index += 1;
} else if (arg.startsWith("--fallback=")) {
options.fallbackGroup = arg.slice("--fallback=".length);
} else {
throw new Error(`Unknown option: ${arg}`);
}
}
if ((options.route && !options.dir) || (!options.route && options.dir)) {
throw new Error("--route and --dir must be used together");
}
return options;
}
function requireValue(argv, index) {
const value = argv[index + 1];
if (!value || value.startsWith("-")) {
throw new Error(`Missing value for ${argv[index]}`);
}
return value;
}
View on GitHub (pinned to 6617f5fd0b)
Solutions
- Run `node scripts/sync-sidebar.js --help` and use only listed options; pass directories via --dir, not positionally
- Through npm, separate flags: `npm run sidebar:sync -- --check`
- Drop dry-run style flags — omitting --write already means dry-run
Example fix
# before (positional dir not supported) node scripts/sync-sidebar.js docs/src/sidebar/itwanger/ai # after node scripts/sync-sidebar.js --route=/sidebar/itwanger/ai/ --dir=docs/src/sidebar/itwanger/ai
Defensive patterns
Strategy: validation
Validate before calling
const ALLOWED = ["--help", "-h", "--write", "--check", "--verbose", "--sidebar", "--route", "--dir", "--fallback"];
const unknown = argv.filter((a) => !ALLOWED.some((o) => a === o || a.startsWith(o + "=")));
if (unknown.length) throw new Error(`Not supported by sync-sidebar.js: ${unknown.join(", ")}`); Try / catch
catch (err) { if (err.message.startsWith("Unknown option:")) { execSync("node scripts/sync-sidebar.js --help"); process.exit(2); } throw err; } Prevention
- This script takes NO positional args — directories go through --dir
- Use npm run sidebar:sync -- <flags>
- Dry-run is the default; do not pass a --dry-run flag
When it happens
Trigger: `node scripts/sync-sidebar.js --dry` (no dry-run concept; dry-run is default without --write); `node scripts/sync-sidebar.js docs/src/sidebar/itwanger/ai` (positional paths are not accepted here); typo like `--chek` for --check; missing `--` separator when running through npm.
Common situations: Assuming this script takes directory positional args like the image converter; typoed flags; npm swallowing flags (`npm run sidebar:check --check` instead of `npm run sidebar:check -- --check`).
Related errors
- Unknown option: ${arg}
- Missing value for ${argv[index]}
- --route and --dir must be used together
- Missing value for ${argv[index]}
- ${optionName} must be a positive integer
AI-assisted analysis of itwanger/toBeBetterJavaer@6617f5fd0b (2026-08-14).
Data as JSON: /api/errors/12ff8ba4bbce93b3.
Report an issue: GitHub.