yarnpkg/yarn · error · MessageError
Command ${JSON.stringify(action)} not found.
Error message
Command ${JSON.stringify(action)} not found. What it means
`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.
Source
Thrown at src/cli/commands/run.js:163
});
}
} else if (action === 'env') {
reporter.log(JSON.stringify(await makeEnv('env', config.cwd, config), null, 2), {force: true});
} else {
let suggestion;
for (const commandName of scripts.keys()) {
const steps = leven(commandName, action);
if (steps < 2) {
suggestion = commandName;
}
}
let msg = `Command ${JSON.stringify(action)} not found.`;
if (suggestion) {
msg += ` Did you mean ${JSON.stringify(suggestion)}?`;
}
throw new MessageError(msg);
}
}
// list possible scripts if none specified
if (args.length === 0) {
if (binCommands.size > 0) {
reporter.info(`${reporter.lang('binCommands') + Array.from(binCommands).join(', ')}`);
} else {
reporter.error(reporter.lang('noBinAvailable'));
}
const printedCommands: Map<string, string> = new Map();
for (const pkgCommand of pkgCommands) {
const action = scripts.get(pkgCommand);
invariant(action, 'Action must exists');
printedCommands.set(pkgCommand, action);
}View on GitHub (pinned to c2dda503f3)
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.
Example fix
// before $ yarn run buil // Command "buil" not found. Did you mean "build"? // after $ yarn run build
Defensive patterns
Strategy: validation
Validate before calling
const pkg = require('./package.json');
const fs = require('fs');
const path = require('path');
function resolveScriptOrBin(action, pkg) {
if (pkg.scripts && pkg.scripts[action]) return {kind: 'script', value: pkg.scripts[action]};
const binDir = path.join('node_modules', '.bin');
if (fs.existsSync(path.join(binDir, action))) return {kind: 'bin', value: action};
return null;
}
if (!resolveScriptOrBin(action, pkg)) {
throw new Error(`Command '${action}' not found in scripts or node_modules/.bin.`);
} Type guard
function scriptExists(action, pkg) {
return typeof pkg === 'object' && pkg !== null &&
typeof pkg.scripts === 'object' &&
Object.prototype.hasOwnProperty.call(pkg.scripts, action);
} Try / catch
try {
await runYarn(['run', action]);
} catch (e) {
if (/Command .* not found/.test(e.message)) {
console.error(`No script/bin '${action}'. Run 'yarn run' to list available commands.`);
return;
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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`.
Common situations: 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.
Related errors
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/bfda50209b679d42.
Report an issue: GitHub.