yarnpkg/yarn · error · MessageError

workspaceMissingCommand

Error message

workspaceMissingCommand

What it means

Thrown by 'yarn workspace' when a workspace name is given but no command follows (fewer than 2 positional args). The command requires something to actually run inside the workspace.

Source

Thrown at src/cli/commands/workspace.js:29

export function setFlags(commander: Object) {}

export function hasWrapper(commander: Object, args: Array<string>): boolean {
  return true;
}

export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
  const {workspaceRootFolder} = config;

  if (!workspaceRootFolder) {
    throw new MessageError(reporter.lang('workspaceRootNotFound', config.cwd));
  }

  if (args.length < 1) {
    throw new MessageError(reporter.lang('workspaceMissingWorkspace'));
  }

  if (args.length < 2) {
    throw new MessageError(reporter.lang('workspaceMissingCommand'));
  }

  const manifest = await config.findManifest(workspaceRootFolder, false);
  invariant(manifest && manifest.workspaces, 'We must find a manifest with a "workspaces" property');

  const workspaces = await config.resolveWorkspaces(workspaceRootFolder, manifest);
  const [workspaceName, ...rest] = args || [];

  if (!Object.prototype.hasOwnProperty.call(workspaces, workspaceName)) {
    throw new MessageError(reporter.lang('workspaceUnknownWorkspace', workspaceName));
  }

  const workspace = workspaces[workspaceName];

  try {
    await child.spawn(NODE_BIN_PATH, [YARN_BIN_PATH, ...rest], {
      stdio: 'inherit',
      cwd: workspace.loc,

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Append the command to run: 'yarn workspace <name> <command> [args...]'.
  2. For a package script use 'yarn workspace <name> run <script>'.

Example fix

# before
$ yarn workspace my-app
# after
$ yarn workspace my-app build
Defensive patterns

Strategy: validation

Validate before calling

if (args.length < 2) {
  throw new Error("'yarn workspace' requires a command to run: yarn workspace <name> <command> [args...]");
}

Type guard

function hasWorkspaceCommand(args: string[]): boolean {
  return Array.isArray(args) && args.length >= 2;
}

Prevention

When it happens

Trigger: Running 'yarn workspace my-app' with no command, so args.length < 2.

Common situations: User stopped at the workspace name; intended 'yarn workspace run <script>' but Yarn's workspace command takes the command directly.

Related errors


AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13). Data as JSON: /api/errors/1db62fca9aa002bb. Report an issue: GitHub.