{"record":{"id":"bfda50209b679d42","repo":"yarnpkg/yarn","slug":"command-json-stringify-action-not-found","errorCode":null,"errorMessage":"Command ${JSON.stringify(action)} not found.","messagePattern":"Command (.+?) not found\\.","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/run.js","lineNumber":163,"sourceCode":"        });\n      }\n    } else if (action === 'env') {\n      reporter.log(JSON.stringify(await makeEnv('env', config.cwd, config), null, 2), {force: true});\n    } else {\n      let suggestion;\n\n      for (const commandName of scripts.keys()) {\n        const steps = leven(commandName, action);\n        if (steps < 2) {\n          suggestion = commandName;\n        }\n      }\n\n      let msg = `Command ${JSON.stringify(action)} not found.`;\n      if (suggestion) {\n        msg += ` Did you mean ${JSON.stringify(suggestion)}?`;\n      }\n      throw new MessageError(msg);\n    }\n  }\n\n  // list possible scripts if none specified\n  if (args.length === 0) {\n    if (binCommands.size > 0) {\n      reporter.info(`${reporter.lang('binCommands') + Array.from(binCommands).join(', ')}`);\n    } else {\n      reporter.error(reporter.lang('noBinAvailable'));\n    }\n\n    const printedCommands: Map<string, string> = new Map();\n\n    for (const pkgCommand of pkgCommands) {\n      const action = scripts.get(pkgCommand);\n      invariant(action, 'Action must exists');\n      printedCommands.set(pkgCommand, action);\n    }","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/run.js#L145-L181","documentation":"`yarn run <action>` first looks up `<action>` in package.json scripts and in the package's `bin` entries. If neither matches (run.js, the else branch reaching :159-163), it builds a `Command \"<action>\" not found.` message, optionally appending a leven-distance suggestion (`Did you mean ...?`) for a script within 2 edit steps.","triggerScenarios":"Running `yarn run foobar` (or `yarn foobar`) where `foobar` is neither a script in package.json nor a dependency binary; typo like `yarn run buil` instead of `build`.","commonSituations":"Typo'd script name; script not yet added to package.json; relying on a binary from a dependency that isn't installed; running before `yarn install` placed bins in node_modules/.bin.","solutions":["Check the suggestion in the message—if present, use the recommended script name.","List available scripts with `yarn run` (no args) and pick the exact name.","Add the missing script to package.json `scripts` if it should exist.","If it's a dependency binary, ensure the package is installed (`yarn install`) so its bin lands in node_modules/.bin."],"exampleFix":"// before\n$ yarn run buil   // Command \"buil\" not found. Did you mean \"build\"?\n// after\n$ yarn run build","handlingStrategy":"validation","validationCode":"const pkg = require('./package.json');\nconst fs = require('fs');\nconst path = require('path');\nfunction resolveScriptOrBin(action, pkg) {\n  if (pkg.scripts && pkg.scripts[action]) return {kind: 'script', value: pkg.scripts[action]};\n  const binDir = path.join('node_modules', '.bin');\n  if (fs.existsSync(path.join(binDir, action))) return {kind: 'bin', value: action};\n  return null;\n}\nif (!resolveScriptOrBin(action, pkg)) {\n  throw new Error(`Command '${action}' not found in scripts or node_modules/.bin.`);\n}","typeGuard":"function scriptExists(action, pkg) {\n  return typeof pkg === 'object' && pkg !== null &&\n    typeof pkg.scripts === 'object' &&\n    Object.prototype.hasOwnProperty.call(pkg.scripts, action);\n}","tryCatchPattern":"try {\n  await runYarn(['run', action]);\n} catch (e) {\n  if (/Command .* not found/.test(e.message)) {\n    console.error(`No script/bin '${action}'. Run 'yarn run' to list available commands.`);\n    return;\n  }\n  throw e;\n}","preventionTips":["List scripts with `yarn run` before invoking unfamiliar names.","Use the leven 'Did you mean?' hint to fix typos.","Ensure dependencies providing bins are installed before running their commands.","Add new scripts to package.json `scripts` rather than relying on ad-hoc names."],"tags":["cli","run","scripts","did-you-mean"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}