mastra-ai/mastra · error · Error

Could not find workspace root

Error message

Could not find workspace root

What it means

collectTransitiveWorkspaceDependencies walks workspace packages transitively and needs the pnpm workspace root (where pnpm-workspace.yaml lives) to instantiate DepsService. If findWorkspacesRoot() cannot locate a workspace root, this plain Error is thrown. It only runs when workspace (link:) dependencies are present, so it implies your project should be a pnpm workspace.

Source

Thrown at packages/deployer/src/bundler/workspaceDependencies.ts:129

}): TransitiveDependencyResult => {
  const usedWorkspacePackages = new Set<string>();
  const queue: string[] = Array.from(initialDependencies);
  const resolutions: Record<string, string> = {};

  while (queue.length > 0) {
    const len = queue.length;
    for (let i = 0; i < len; i += 1) {
      const pkgName = queue.shift();
      if (!pkgName || usedWorkspacePackages.has(pkgName)) {
        continue;
      }

      const dep = workspaceMap.get(pkgName);
      if (!dep) continue;

      const root = findWorkspacesRoot();
      if (!root) {
        throw new Error('Could not find workspace root');
      }

      const depsService = new DepsService(root.location);
      depsService.__setLogger(logger);
      const sanitizedName = slugify(pkgName);

      const tgzPath = depsService.getWorkspaceDependencyPath({
        pkgName: sanitizedName,
        version: dep.version!,
      });
      resolutions[pkgName] = tgzPath;
      usedWorkspacePackages.add(pkgName);

      for (const [depName, _depVersion] of Object.entries(dep?.dependencies ?? {})) {
        if (!usedWorkspacePackages.has(depName) && workspaceMap.has(depName)) {
          queue.push(depName);
        }
      }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Ensure a pnpm-workspace.yaml exists at your project/monorepo root and run the command from within that tree.
  2. If this is a standalone (non-monorepo) project, replace any "workspace:*" / "workspace:^" dependency versions with real semver versions.
  3. Confirm the package manager is pnpm and the workspace file wasn't excluded by .npmignore/docker COPY filters.

Example fix

// before: package.json
"some-pkg": "workspace:*"
// after
"some-pkg": "^1.4.0"
Defensive patterns

Strategy: validation

Validate before calling

import { findWorkspacesRoot } from './bundler/workspaceDependencies';
if (!findWorkspacesRoot()) throw new Error('Run from inside a pnpm workspace (pnpm-workspace.yaml missing)');
for (const [name, ver] of Object.entries(pkg.dependencies ?? {})) {
  if (String(ver).startsWith('workspace:')) throw new Error(`Replace workspace: dep ${name} for standalone builds`);
}

Try / catch

try {
  await mastra.deploy();
} catch (e) {
  if (e?.message === 'Could not find workspace root') {
    console.error('Run mastra build from the monorepo root or inline your workspace deps.');
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the bundler/deploy pipeline on a project that has workspace: protocol dependencies (or is inside a monorepo) but where findWorkspacesRoot() finds no pnpm-workspace.yaml / packageManager field from the current directory upward.

Common situations: Running mastra build from a subdirectory whose parents lack pnpm-workspace.yaml; a standalone app that accidentally kept a "workspace:^" dependency copied from a monorepo; using npm/yarn workspaces where the finder expects pnpm conventions.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/9d2010ab3f6ab75b. Report an issue: GitHub.