yarnpkg/yarn · error · MessageError

workspaceMissingWorkspace

Error message

workspaceMissingWorkspace

What it means

Thrown by 'yarn workspace' when fewer than one positional argument is supplied. The command form is 'yarn workspace <workspace-name> <command> [args...]'; omitting the workspace name is rejected before any resolution.

Source

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

import {NODE_BIN_PATH, YARN_BIN_PATH} from '../../constants';

const invariant = require('invariant');

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];

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Supply both a workspace name and a command: 'yarn workspace <name> <command>'.
  2. List available workspaces first with 'yarn workspaces info' to get the exact name.

Example fix

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

Strategy: validation

Validate before calling

if (args.length < 1) {
  throw new Error("'yarn workspace' requires a workspace name and a command: yarn workspace <name> <command>");
}

Type guard

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

Prevention

When it happens

Trigger: Running bare 'yarn workspace' (no further args), so args.length < 1.

Common situations: User forgot the workspace name; confusion with 'yarn workspaces' (plural) which has different subcommands.

Related errors


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