JuliusBrussee/caveman · error · Error
Windows command shim target missing
Error message
Windows command shim target missing: ${script} What it means
After extracting the script path from a Windows Node .cmd shim, `portableInvocation` stats the target .js file to confirm it exists before re-spawning node with it. This error means the shim exists but the script it points at is missing, so the delegation cannot proceed safely.
Solutions
- Reinstall the owning package: npm ci (or npm install) to restore the missing script
- Verify the path printed in the error and check whether the file exists at that exact location
- Remove the stale .cmd shim from node_modules/.bin if its package was uninstalled
- If the shim was copied/moved, restore it next to its target or use an absolute script path
Example fix
// before
spawn("lefthook", ["install"], opts); // stale shim, target gone
// after
execSync("npm ci"); // restore script, then spawn again
spawn("lefthook", ["install"], opts); Defensive patterns
Strategy: validation
Validate before calling
import { statSync } from "node:fs";
import { dirname, resolve } from "node:path";
function shimTargetExists(shimPath, targetRelative) {
const script = /^[A-Za-z]:[\\/]/.test(targetRelative)
? targetRelative
: resolve(dirname(shimPath), ...targetRelative.split(/[\\/]+/));
try { return statSync(script).isFile(); } catch { return false; }
} Try / catch
try {
const inv = portableInvocation(command, args);
spawn(inv.command, inv.args, opts);
} catch (e) {
if (String(e.message).startsWith("Windows command shim target missing:")) {
console.error("Stale shim — run npm ci to restore the package entry script");
} else throw e;
} Prevention
- Run npm ci in CI rather than reusing pruned node_modules
- Don't copy .bin shims out of node_modules — their targets are resolved relative to the shim
- After upgrades, clean installs fix moved entry scripts
- Check that antivirus/prune tools aren't deleting .js files from node_modules
When it happens
Trigger: A .cmd shim whose relative target (resolved against the shim's dirname if not absolute) fails statSync's isFile check — target deleted, moved, or the shim was written with a wrong relative path.
Common situations: node_modules partially pruned (npm prune or manual deletion) leaving orphaned .bin shims; package upgrades that moved the entry script; a shim copied to another directory so %~dp0-relative resolution no longer matches; broken install after a crashed npm run.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- cannot safely launch non-Node Windows command shim
- cannot safely launch Windows command shim
- ENOENT
- non-Node Windows command shim
- unsafe Windows command shim
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/23b9cde518a44fdf.
Report an issue: GitHub.
Appendix: source
Thrown at agents/delegate/portable-process.mjs:53
const match = line.match(/"%(?:dp0%|~dp0)\\([^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i)
|| line.match(/"([A-Za-z]:[\\/][^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i);
if (match) return match[1];
}
return null;
}
export function portableInvocation(command, args, platform = process.platform, env = process.env) {
if (platform !== "win32") return { command, args: [...args] };
const executable = resolveWindowsCommand(command, env) ?? command;
if (!/\.(?:cmd|bat)$/i.test(executable)) return { command: executable, args: [...args] };
const stat = statSync(executable);
if (!stat.isFile() || stat.size > 256 * 1024) throw new Error(`unsafe Windows command shim: ${executable}`);
const relativeScript = parseWindowsNodeShim(readFileSync(executable, "utf8"));
if (!relativeScript) throw new Error(`non-Node Windows command shim: ${executable}`);
const script = /^[A-Za-z]:[\\/]/.test(relativeScript)
? relativeScript
: resolve(dirname(executable), ...relativeScript.split(/[\\/]+/));
if (!statSync(script).isFile()) throw new Error(`Windows command shim target missing: ${script}`);
return { command: process.execPath, args: [script, ...args] };
}
export function delegateSpawnOptions(platform = process.platform) {
return {
detached: platform !== "win32",
windowsHide: true,
};
}
export async function killProcessTree(
child,
platform = process.platform,
taskkill = spawnSync,
kill = process.kill,
graceMs = 1500,
) {
if (!child?.pid) return;View on GitHub (pinned to 3ee70a1026)