itwanger/toBeBetterJavaer · error · Error
Path not found: ${target}
Error message
Path not found: ${target} What it means
Thrown by collectMarkdownFiles() in scripts/convert-mdnice-images-to-cdn.js when a positional target (or the default docs/src) does not exist on disk. Targets are resolved to absolute paths against the repo root before the existence check, so relative paths are interpreted from the repo root, not the current working directory.
Source
Thrown at scripts/convert-mdnice-images-to-cdn.js:176
function validateOssConfig(config) {
const required = [
"PAICODING_OSS_AK",
"PAICODING_OSS_SK",
"PAICODING_OSS_ENDPOINT",
"PAICODING_OSS_BUCKET",
"PAICODING_OSS_HOST",
];
const missing = required.filter((key) => !config[key]);
if (missing.length > 0) {
throw new Error(`Missing required env vars: ${missing.join(", ")}`);
}
}
function collectMarkdownFiles(targets) {
const files = [];
for (const target of targets) {
if (!fs.existsSync(target)) {
throw new Error(`Path not found: ${target}`);
}
const stat = fs.statSync(target);
if (stat.isDirectory()) {
walkDir(target, files);
} else if (target.endsWith(".md")) {
files.push(target);
}
}
return [...new Set(files)].sort();
}
function walkDir(dir, files) {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
const relativePath = path.relative(ROOT_DIR, fullPath);
if (entry.isDirectory()) {
if (!shouldSkipDir(relativePath)) {View on GitHub (pinned to 6617f5fd0b)
Solutions
- Check the path exists: `ls <repo-root>/<your-target>` and fix the typo
- Pass paths relative to the repo root (path.resolve(ROOT_DIR, arg)) or absolute paths
- Run with no targets to use the default docs/src and confirm the baseline works
Example fix
# before node scripts/convert-mdnice-images-to-cdn.js docss/src # after node scripts/convert-mdnice-images-to-cdn.js docs/src
Defensive patterns
Strategy: validation
Validate before calling
const target = path.resolve(REPO_ROOT, userArg);
if (!fs.existsSync(target)) { console.error(`No such path (resolved to ${target}; paths resolve from the repo root): ${userArg}`); process.exit(2); } Type guard
const isExistingPath = (p) => fs.existsSync(path.resolve(REPO_ROOT, p));
Try / catch
catch (err) { if (err.message.startsWith("Path not found:")) { console.error("Path resolves against the repo root — check spelling and base dir"); process.exit(2); } throw err; } Prevention
- Tab-complete paths in the shell instead of typing them
- Remember targets resolve from the repo root regardless of cwd
- Run with no targets first to confirm the default docs/src works
When it happens
Trigger: `node scripts/convert-mdnice-images-to-cdn.js docs/src/some/typo.md`; passing a relative path like `./docs` which resolves to <repo-root>/./docs — usually fine, but `../docs` or a path from a different cwd breaks; the default target docs/src missing because the script is run outside a full checkout.
Common situations: Running the script from a different directory with a cwd-relative path in mind; typos in file/dir names; passing a path with a trailing typo or wrong case on case-sensitive filesystems; repo layout changed.
Related errors
- Unknown option: ${arg}
- Missing value for ${argv[index]}
- ${optionName} must be a positive integer
- Unknown option: ${arg}
- --route and --dir must be used together
AI-assisted analysis of itwanger/toBeBetterJavaer@6617f5fd0b (2026-08-14).
Data as JSON: /api/errors/1c2e744ac1955a1a.
Report an issue: GitHub.