{"record":{"id":"2ad11534b0e65ba3","repo":"JuliusBrussee/caveman","slug":"windows-command-shim-target-is-missing-script-2ad115","errorCode":null,"errorMessage":"Windows command shim target is missing: ${script}","messagePattern":"Windows command shim target is missing: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/pi-extension/src/portable-command.ts","lineNumber":94,"sourceCode":"  platform: NodeJS.Platform = process.platform,\n  env: NodeJS.ProcessEnv = process.env,\n): PortableInvocation {\n  if (platform !== \"win32\") return { command, args: [...args] };\n  const executable = resolveWindowsCommand(command, env) ?? command;\n  if (!/\\.(?:cmd|bat)$/i.test(executable)) return { command: executable, args: [...args] };\n  const stat = statSync(executable);\n  if (!stat.isFile() || stat.size > 256 * 1024) {\n    throw new Error(`cannot safely launch Windows command shim: ${executable}`);\n  }\n  const shimScript = parseWindowsNodeShim(readFileSync(executable, \"utf8\"));\n  if (!shimScript) {\n    throw new Error(`cannot safely launch non-Node Windows command shim: ${executable}; install a native .exe`);\n  }\n  const script = /^[A-Za-z]:[\\\\/]/.test(shimScript)\n    ? shimScript\n    : resolve(dirname(executable), ...shimScript.split(/[\\\\/]+/));\n  if (!statSync(script).isFile()) {\n    throw new Error(`Windows command shim target is missing: ${script}`);\n  }\n  return { command: process.execPath, args: [script, ...args] };\n}\n","sourceCodeStart":76,"sourceCodeEnd":98,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/pi-extension/src/portable-command.ts#L76-L98","documentation":"After parsing a Windows Node shim, `portableInvocation` resolves the shim's target script (absolute if the shim says so, otherwise relative to the shim's directory) and stats it at packages/pi-extension/src/portable-command.ts:94. If the target is not a regular file, the shim is dangling — it would launch Node against a nonexistent script — so the library throws this Error with the resolved path.","triggerScenarios":"A `.cmd` shim referencing a JS entry point that no longer exists (package uninstalled/renamed, node_modules pruned, or the shim written for a different install layout).","commonSituations":"Partial `npm uninstall`/upgrade leaving orphaned shims; moving or renaming a project directory that a shim points into; pnpm/yarn layouts differing from npm's expected paths.","solutions":["Reinstall the tool the shim belongs to so the target script is restored.","Delete stale shims from the global/local bin directory and reinstall cleanly.","Verify the resolved target path exists (`fs.existsSync(scriptPath)`) before invoking, and point config at the correct entry."],"exampleFix":"// before\n// dangling shim: my-cli.cmd -> ./node_modules/my-cli/bin/cli.js (deleted)\n// after\nnpm i -D my-cli   // restores node_modules/my-cli/bin/cli.js","handlingStrategy":"validation","validationCode":"import { statSync } from 'node:fs';\nfunction shimTargetExists(shimPath: string, target: string) {\n  const resolved = /^[A-Za-z]:[\\\\/]/.test(target) ? target : resolve(dirname(shimPath), target);\n  try { return statSync(resolved).isFile(); } catch { return false; }\n}","typeGuard":"const fileExists = (p: string): boolean => { try { return statSync(p).isFile(); } catch { return false; } };","tryCatchPattern":"try {\n  const inv = portableInvocation(command, args, env);\n} catch (e) {\n  if (e instanceof Error && /shim target is missing/.test(e.message)) {\n    console.error(`${command} shim is dangling; reinstall the package.`);\n    throw e;\n  }\n  throw e;\n}","preventionTips":["Reinstall or repair packages after moves/renames so shims point at existing files.","Prune orphaned .cmd shims when uninstalling global tools.","Run a startup health check that stats each configured command's entry point."],"tags":["windows","command-shim","file-not-found","launch"],"backgroundTag":"file-not-found","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}