{"record":{"id":"ff527a7305e68c04","repo":"withfig/autocomplete","slug":"script-not-found-token","errorCode":null,"errorMessage":"Script not found: '${token}'","messagePattern":"Script not found: '(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/yarn.ts","lineNumber":20,"sourceCode":"\nexport const yarnScriptParserDirectives: Fig.Arg[\"parserDirectives\"] = {\n  alias: async (token, executeShellCommand) => {\n    const npmPrefix = await executeShellCommand({\n      command: \"npm\",\n      // eslint-disable-next-line @withfig/fig-linter/no-useless-arrays\n      args: [\"prefix\"],\n    });\n    if (npmPrefix.status !== 0) {\n      throw new Error(\"npm prefix command failed\");\n    }\n    const packageJson = await executeShellCommand({\n      command: \"cat\",\n      // eslint-disable-next-line @withfig/fig-linter/no-useless-arrays\n      args: [`${npmPrefix.stdout.trim()}/package.json`],\n    });\n    const script: string = JSON.parse(packageJson.stdout).scripts?.[token];\n    if (!script) {\n      throw new Error(`Script not found: '${token}'`);\n    }\n    return script;\n  },\n};\n\nexport const nodeClis = new Set([\n  \"vue\",\n  \"vite\",\n  \"nuxt\",\n  \"react-native\",\n  \"degit\",\n  \"expo\",\n  \"jest\",\n  \"next\",\n  \"electron\",\n  \"prisma\",\n  \"eslint\",\n  \"prettier\",","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/withfig/autocomplete/blob/aef52acff84c45edde61ae610cc2c964802b9a38/src/yarn.ts#L2-L38","documentation":"After loading `${npmPrefix}/package.json`, the generator reads `scripts[token]` to resolve the requested npm script. If the parsed JSON has no `scripts` object or no entry matching the typed token, the spec throws this Error because completion cannot resolve the script's command.","triggerScenarios":"The typed token is not a key of the `scripts` field in package.json at the npm prefix directory, or package.json has no `scripts` field at all (`undefined` fails the `if (!script)` check).","commonSituations":"User typed a script that exists in the local project but not in the global-prefix package.json the generator reads; typo in script name; scripts removed/renamed in a package.json version bump; monorepo scripts defined only in workspace packages.","solutions":["Run `npm run` (or `yarn run`) with no arguments to list available scripts and confirm the exact name","Check that the script exists in the package.json file the generator reads (`cat $(npm prefix)/package.json`) — note it is the global prefix, not your project, so scripts defined in a local project will not be found here","Fix the typo or add the missing script to the scripts field","If your scripts live in a local package.json, verify the spec's prefix resolution matches your project layout"],"exampleFix":"// before\nconst script: string = JSON.parse(packageJson.stdout).scripts?.[token];\n// after (fall back to the local project's package.json)\nconst parsed = JSON.parse(packageJson.stdout);\nconst script: string =\n  parsed.scripts?.[token] ??\n  JSON.parse((await executeShellCommand({ command: \"cat\", args: [\"package.json\"] })).stdout).scripts?.[token];","handlingStrategy":"validation","validationCode":"import { readFileSync } from \"fs\";\nexport function scriptExists(prefix: string, token: string): boolean {\n  const pkg = JSON.parse(readFileSync(`${prefix}/package.json`, \"utf8\"));\n  return Boolean(pkg.scripts && token in pkg.scripts);\n}\n// call before resolving: if (!scriptExists(npmPrefix, token)) return [];","typeGuard":"function hasScript(pkg: unknown, token: string): pkg is { scripts: Record<string, string> } & Record<string, unknown> {\n  return typeof pkg === \"object\" && pkg !== null &&\n    \"scripts\" in pkg && typeof (pkg as any).scripts === \"object\" &&\n    token in (pkg as any).scripts && typeof (pkg as any).scripts[token] === \"string\";\n}","tryCatchPattern":"try {\n  const script = await resolveScript(token);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith(\"Script not found:\")) {\n    // unknown token: return the list of available scripts instead of throwing\n    return listAvailableScripts();\n  }\n  throw err;\n}","preventionTips":["Confirm the exact script name with `npm run` before completion; names are case-sensitive","Remember the generator reads $(npm prefix)/package.json (global), not your local project — local-only scripts will not resolve","Wrap JSON.parse in try/catch so malformed package.json surfaces a clearer message","Keep scripts defined in a stable place and re-run `npm run` after dependency updates that may rewrite package.json"],"tags":["npm","yarn","json-parsing","package-json","scripts"],"backgroundTag":"missing-config-key","analyzedSha":"aef52acff84c45edde61ae610cc2c964802b9a38","analyzedAt":"2026-08-31T11:00:43.303Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}