yarnpkg/yarn · error · MessageError

workspaceRootNotFound

Error message

workspaceRootNotFound

What it means

Thrown by 'yarn workspace' when config.workspaceRootFolder is falsy. Yarn walks up from cwd looking for a manifest declaring a 'workspaces' field; if none is found, there is no workspace root to operate from.

Source

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

import type Config from '../../config.js';
import {MessageError} from '../../errors.js';
import type {Reporter} from '../../reporters/index.js';
import * as child from '../../util/child.js';
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));

View on GitHub (pinned to c2dda503f3)

Solutions

  1. Run the command from inside the workspace project root.
  2. Add a 'workspaces' field (array of globs) to the root package.json and run 'yarn install'.
  3. Confirm the project actually intends to use workspaces.

Example fix

// before (root package.json)
{ "name": "root", "private": true }
// after
{
  "name": "root",
  "private": true,
  "workspaces": ["packages/*"]
}
Defensive patterns

Strategy: validation

Validate before calling

if (!config.workspaceRootFolder) {
  throw new Error(`No workspace root found from ${config.cwd}; add a 'workspaces' field to the root manifest.`);
}

Type guard

function hasWorkspaceRoot(config: Config): boolean {
  return typeof config.workspaceRootFolder === 'string' && config.workspaceRootFolder.length > 0;
}

Prevention

When it happens

Trigger: Running 'yarn workspace <name> <cmd>' in a directory tree whose root package.json has no 'workspaces' field (or where cwd is outside the project entirely).

Common situations: Not a monorepo; root package.json is missing the 'workspaces' key; running from a temp/external directory; using the wrong Yarn version that does not auto-detect workspaces.

Related errors


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