itwanger/toBeBetterJavaer · critical · Error
Missing required env vars: ${missing.join(", ")}
Error message
Missing required env vars: ${missing.join(", ")} What it means
Thrown by validateOssConfig() in scripts/convert-mdnice-images-to-cdn.js before any network work when one or more of the five required OSS env vars (PAICODING_OSS_AK, PAICODING_OSS_SK, PAICODING_OSS_ENDPOINT, PAICODING_OSS_BUCKET, PAICODING_OSS_HOST) is missing or empty. The message lists exactly which keys are absent. The config is loaded from an env file (default .env at repo root, overridable with --env) merged with process.env.
Source
Thrown at scripts/convert-mdnice-images-to-cdn.js:168
) {
value = value.slice(1, -1);
}
env[key] = value;
}
return env;
}
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();
}View on GitHub (pinned to 6617f5fd0b)
Solutions
- Create .env in the repo root with all five keys listed in the error, then rerun
- If your env file lives elsewhere, pass it explicitly: `--env=path/to/.env` (resolved relative to the repo root)
- Verify with a dry run first — validation only fires for --write runs, so `node scripts/convert-mdnice-images-to-cdn.js` (no flags) confirms scanning works while you fix credentials
Example fix
# .env (repo root) — before: missing keys PAICODING_OSS_AK=... # after: all five required keys present PAICODING_OSS_AK=LTAI... PAICODING_OSS_SK=... PAICODING_OSS_ENDPOINT=oss-cn-hangzhou.aliyuncs.com PAICODING_OSS_BUCKET=my-bucket PAICODING_OSS_HOST=https://cdn.example.com
Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight config check before invoking with --write
const REQUIRED = ["PAICODING_OSS_AK", "PAICODING_OSS_SK", "PAICODING_OSS_ENDPOINT", "PAICODING_OSS_BUCKET", "PAICODING_OSS_HOST"];
const missing = REQUIRED.filter((k) => !process.env[k] && !envFileHas(k));
if (missing.length) { console.error(`Configure first: ${missing.join(", ")}`); process.exit(2); } Type guard
const hasOssConfig = (cfg) => ["PAICODING_OSS_AK","PAICODING_OSS_SK","PAICODING_OSS_ENDPOINT","PAICODING_OSS_BUCKET","PAICODING_OSS_HOST"].every((k) => Boolean(cfg[k]));
Try / catch
catch (err) { if (err.message.startsWith("Missing required env vars")) { console.error("Create .env with the listed keys (see README); nothing was uploaded."); process.exit(2); } throw err; } Prevention
- Keep a .env.example committed listing the five PAICODING_OSS_* keys
- Always do a dry run (omit --write) before the first --write run
- Never print the secret values — check presence only
When it happens
Trigger: Running with --write before creating .env; pointing --env at a wrong path (loadEnv silently returns {} for a missing file, so no error until this check); .env exists but a key is misspelled (e.g. PAICODING_OSS_HOST_URL) or has an empty value; key present in .env but not exported when the vars were expected from the shell.
Common situations: Fresh clone without .env; CI runner secrets not wired; renaming the OSS provider; values commented out in .env; Windows line endings or `export ` prefixes that the simple line parser does not handle.
Related errors
- Sidebar file not found: ${options.sidebar}
- Markdown directory not found: ${target.dir}
- Route not found in sidebar.ts: ${target.route}
AI-assisted analysis of itwanger/toBeBetterJavaer@6617f5fd0b (2026-08-14).
Data as JSON: /api/errors/7c4091796d88c90b.
Report an issue: GitHub.