yarnpkg/yarn · error · MessageError

workspaceUnknownWorkspace

Error message

workspaceUnknownWorkspace

What it means

Thrown by 'yarn workspace' when the supplied workspace name is not a key in the object returned by config.resolveWorkspaces(workspaceRootFolder, manifest). The named workspace is not declared by the root 'workspaces' globs (or has not been installed).

Source

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

    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,
    });
  } catch (err) {
    throw err;
  }
}

View on GitHub (pinned to c2dda503f3)

Solutions

  1. List valid workspace names with 'yarn workspaces info' and use the exact key.
  2. Ensure the workspace package is covered by the root 'workspaces' glob and has its own package.json with a 'name'.
  3. Run 'yarn install' so workspaces are resolved into the lockfile.

Example fix

# before
$ yarn workspace myapp build      # folder is 'app', name is 'my-app'
# after
$ yarn workspace my-app build
Defensive patterns

Strategy: validation

Validate before calling

const manifest = await config.findManifest(workspaceRootFolder, false);
const workspaces = await config.resolveWorkspaces(workspaceRootFolder, manifest);
if (!Object.prototype.hasOwnProperty.call(workspaces, workspaceName)) {
  throw new Error(`Unknown workspace "${workspaceName}". Known: ${Object.keys(workspaces).join(', ')}`);
}

Type guard

function isKnownWorkspace(workspaces: Record<string, unknown>, name: string): boolean {
  return Object.prototype.hasOwnProperty.call(workspaces, name);
}

Prevention

When it happens

Trigger: Running 'yarn workspace <unknown> <cmd>' where <unknown> does not match any resolved workspace name (typo, not in 'workspaces' glob, or not yet installed).

Common situations: Typo in the workspace name; workspace directory exists but is not covered by the root 'workspaces' glob; 'yarn install' has not been run since adding the workspace; the workspace's own package.json 'name' differs from its folder name (Yarn keys workspaces by package name).

Related errors


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