prisma/prisma · error · Error

Could not find monorepo root (pnpm-workspace.yaml)

Error message

Could not find monorepo root (pnpm-workspace.yaml)

What it means

Thrown by findMonorepoRoot in the CLI's record.ts script when walking up from the start directory to '/' without finding a pnpm-workspace.yaml file. The recording script depends on being run inside the Prisma Next monorepo (it resolves workspace paths relative to the root).

Source

Thrown at packages/1-framework/3-tooling/cli/scripts/record.ts:136

    return execFileSync(process.execPath, [CLI_BIN, ...args.split(/\s+/).filter(Boolean)], {
      cwd,
      encoding: 'utf-8',
      env: { ...process.env, NO_COLOR: '1', CI: 'true' },
      stdio: ['pipe', 'pipe', 'pipe'],
    });
  } catch (error: unknown) {
    const e = error as { stdout?: string; stderr?: string };
    return `${e.stdout ?? ''}${e.stderr ?? ''}`;
  }
}

function findMonorepoRoot(startDir: string): string {
  let dir = startDir;
  while (dir !== '/') {
    if (existsSync(join(dir, 'pnpm-workspace.yaml'))) return dir;
    dir = dirname(dir);
  }
  throw new Error('Could not find monorepo root (pnpm-workspace.yaml)');
}

const MONOREPO_ROOT = findMonorepoRoot(CLI_ROOT);

/**
 * Workspace is created inside the test fixture app so jiti can resolve
 * workspace packages (adapter-postgres, driver-postgres, etc.) when
 * loading prisma-next.config.ts.
 */
const FIXTURE_APP_DIR = join(MONOREPO_ROOT, 'test/integration/test/fixtures/cli/cli-e2e-test-app');

// --- Test utils (loaded dynamically to avoid adding deps to CLI package) ---

interface DbClient {
  query(sql: string): Promise<unknown>;
}

interface TestUtils {

View on GitHub (pinned to a20d61fb6f)

Solutions

  1. Run the script from inside the Prisma Next monorepo (e.g. packages/1-framework/3-tooling/cli).
  2. Ensure pnpm-workspace.yaml exists at the repository root.
  3. If invoking programmatically, confirm the __dirname resolution points inside the repo.

Example fix

// before: run from /tmp
cd /tmp && tsx /path/to/record.ts  // throws
// after: run from the cli package inside the monorepo
pnpm --filter @prisma/cli exec tsx scripts/record.ts
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync } from 'node:fs';
import { dirname, join } from 'node:path';
function hasMonorepoRoot(start: string): boolean {
  let dir = start;
  while (dir !== '/') {
    if (existsSync(join(dir, 'pnpm-workspace.yaml'))) return true;
    dir = dirname(dir);
  }
  return false;
}

Prevention

When it happens

Trigger: Running `tsx scripts/record.ts` (or `npx tsx scripts/record.ts`) from a directory that is not inside the Prisma Next monorepo — e.g. the file was copied elsewhere, or invoked from /tmp or a non-workspace clone.

Common situations: Running the recording script in isolation outside the repo; the script's CLI_ROOT resolution produced an unexpected path; pnpm-workspace.yaml was renamed or deleted.

Related errors


AI-assisted analysis of prisma/prisma@a20d61fb6f (2026-08-11). Data as JSON: /api/errors/36607f70a1bd6f26. Report an issue: GitHub.