{"record":{"id":"62478fbd587b72f3","repo":"yarnpkg/yarn","slug":"execmissingcommand","errorCode":null,"errorMessage":"execMissingCommand","messagePattern":"execMissingCommand","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/exec.js","lineNumber":19,"sourceCode":"// @flow\n\nimport type Config from '../../config.js';\nimport {MessageError} from '../../errors.js';\nimport type {Reporter} from '../../reporters/index.js';\nimport * as child from '../../util/child.js';\nimport {makeEnv} from '../../util/execute-lifecycle-script.js';\n\nexport function setFlags(commander: Object) {}\n\nexport function hasWrapper(commander: Object, args: Array<string>): boolean {\n  return true;\n}\n\nexport async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {\n  const env = await makeEnv(`exec`, config.cwd, config);\n\n  if (args.length < 1) {\n    throw new MessageError(reporter.lang('execMissingCommand'));\n  }\n\n  const [execName, ...rest] = args;\n  await child.spawn(execName, rest, {stdio: 'inherit', env});\n}\n","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/exec.js#L1-L25","documentation":"`yarn exec` shells out to a binary in the project's resolved PATH. At `exec.js:19` it requires at least one argument (the command); `args.length < 1` throws `execMissingCommand` ('Missing command name.') before constructing the env or spawning.","triggerScenarios":"Invoking `yarn exec` with no command token, e.g. `yarn exec` alone, or `yarn exec '$CMD'` where `$CMD` expands to empty.","commonSituations":"An npm script that calls `yarn exec` with a variable that is unset in CI, or running the command interactively by mistake.","solutions":["Provide a command: `yarn exec eslint .`.","If you meant to list scripts, use `yarn run` without arguments instead.","In scripts, default/require the variable: `yarn exec \"${CMD:?CMD required}\"`."],"exampleFix":"// before\n$ yarn exec\n\n// after\n$ yarn exec eslint src","handlingStrategy":"validation","validationCode":"function requireExecCommand(args: string[]): string[] {\n  if (!Array.isArray(args) || args.length < 1) {\n    throw new Error('yarn exec requires a command name');\n  }\n  return args;\n}","typeGuard":"function hasExecCommand(args: unknown): args is [string, ...string[]] {\n  return Array.isArray(args) && typeof args[0] === 'string' && args[0].length > 0;\n}","tryCatchPattern":null,"preventionTips":["In npm scripts, gate `yarn exec \"$CMD\"` with `${CMD:?CMD required}`.","Prefer `yarn run <script>` for known tasks to avoid empty-command pitfalls."],"tags":["yarn-exec","arguments","validation"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}