Estalio
← All insights

Pinning Turbopack's workspace root for Vercel monorepos

2026-06-02·3 min read

We moved a single-app Next.js project into a pnpm monorepo last week. Locally everything built. On Vercel, the production build broke with a confusing error:

Error: Next.js inferred your workspace root, but it may not be correct.
We couldn't find the Next.js package (next/package.json) from the project directory: /vercel/path0/apps/api/app
To fix this, set turbopack.root in your Next.js config, or ensure the Next.js package is resolvable from this directory.

The cause is straightforward once you see it: Turbopack walks up from apps/api looking for the nearest node_modules/next. In a pnpm workspace, those node_modules live at the workspace root, not next to apps/api. Locally Turbopack happens to find them anyway because of how pnpm symlinks resolve from the cwd. On Vercel, the cwd is different, and the walk fails.

The fix is two settings in next.config.ts:

import path from "node:path";

const workspaceRoot = path.join(__dirname, "..", "..");

const nextConfig: NextConfig = {
  transpilePackages: ["@yourorg/shared"],
  outputFileTracingRoot: workspaceRoot,
  turbopack: { root: workspaceRoot },
};

Two things have to match. Vercel injects outputFileTracingRoot automatically and Turbopack will refuse to start if it disagrees with turbopack.root. Set both explicitly to the same path, the workspace root, and the build picks them up cleanly in both environments.

While you're in there, also set the project's Root Directory to apps/api in the Vercel dashboard. Vercel's auto-detect-monorepo flow handles the install step (it'll run pnpm install from the workspace root) but the build still runs scoped to your Root Directory setting.

Two-line fix; an hour to find. Filing this in case anyone else burns the same hour.