{"record":{"id":"4bd8098c73dc175a","repo":"JuliusBrussee/caveman","slug":"windows-command-shim-target-is-missing-script-4bd809","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/cli/src/portable-command.ts","lineNumber":33,"sourceCode":"export function portableInvocation(\n  command: string,\n  args: readonly string[],\n  platform: NodeJS.Platform = process.platform,\n): PortableInvocation {\n  if (platform !== \"win32\" || !/\\.(?:cmd|bat)$/i.test(command)) {\n    return { command, args: [...args] };\n  }\n  const stat = statSync(command);\n  if (!stat.isFile() || stat.size > 256 * 1024) {\n    throw new Error(`cannot safely launch Windows command shim: ${command}`);\n  }\n  const relativeScript = parseWindowsNodeShim(readFileSync(command, \"utf8\"));\n  if (!relativeScript) {\n    throw new Error(`cannot safely launch non-Node Windows command shim: ${command}; install a native .exe`);\n  }\n  const script = resolve(dirname(command), ...relativeScript.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":15,"sourceCodeEnd":37,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/cli/src/portable-command.ts#L15-L37","documentation":"After successfully parsing a Windows Node shim, caveman resolves the referenced script relative to the shim's directory and stats it. If the target .js file does not exist as a regular file, launching would fail cryptically later, so it throws this error naming the resolved absolute script path. It usually indicates a half-installed or moved package.","triggerScenarios":"portableInvocation on win32 where the .cmd shim parses and points to ..\\node_modules\\some-tool\\bin.js (or similar), but statSync reports that path missing — deleted node_modules, partial install, or a copied shim without its package.","commonSituations":"Deleting node_modules while leaving global/local .bin shims behind, interrupted npm install, copying a project directory without node_modules, or package layout changes after an upgrade renaming the bin entry.","solutions":["Reinstall the owning package so the shim's target script exists again (npm install / npm rebuild).","Verify the path in the error: if the entry point moved (package upgrade renamed bin), regenerate shims via npm rebuild or by reinstalling.","Remove the orphaned .cmd shim from PATH so resolution picks a working installation."],"exampleFix":"# before: shim points at removed package\nC:\\proj\\node_modules\\.bin\\tool.cmd  ->  ..\\..\\tool\\bin.js (missing)\n# after: reinstall to restore target\nnpm install tool","handlingStrategy":"try-catch","validationCode":"import { existsSync, statSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\n\nfunction shimTargetExists(command: string, relativeScript: string): boolean {\n  const target = resolve(dirname(command), ...relativeScript.split(/[\\\\/]+/));\n  return existsSync(target) && statSync(target).isFile();\n}","typeGuard":null,"tryCatchPattern":"try {\n  const invocation = portableInvocation(cmd, args);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"Windows command shim target is missing\")) {\n    reinstallOwner(cmd); // npm install of the shim's package, then retry\n    return portableInvocation(cmd, args);\n  }\n  throw e;\n}","preventionTips":["Never delete node_modules while leaving .bin shims on PATH.","After partial installs, regenerate shims (npm rebuild) before invoking tools.","Copy projects with their node_modules or reinstall immediately after copying."],"tags":["windows","shim","missing-file","cli"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}