Skip to content

Turbopack ignores turbopack.root in pnpm monorepo, infers App Router app/ as project directory #92540

@mausferd

Description

@mausferd

Link to the code that reproduces this issue

https://github.com/mausferd/turbopack-pnpm-app-router-repro

To Reproduce

  1. git clone https://github.com/mausferd/turbopack-pnpm-app-router-repro && cd turbopack-pnpm-app-router-repro
  2. pnpm install
  3. cd apps/web && pnpm dev (uses Turbopack — the default)

Current vs. Expected behavior

Expected: Next 16.2.3 starts the dev server. turbopack.root is set in apps/web/next.config.mjs to an absolute path pointing at apps/web, so Turbopack should use apps/web as the project root, find apps/web/node_modules/next/package.json via the standard pnpm symlink, and serve app/page.tsx.

Actual: dev server reports Ready in ~170ms, then immediately crashes with:

Error: Turbopack build failed with 1 errors:
./app
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: /private/tmp/turbopack-pnpm-app-router-repro/apps/web/app
     To fix this, set turbopack.root in your Next.js config, or ensure the Next.js package is resolvable from this directory.

Two things to note in the error message:

  1. The "project directory" is apps/web/app, not apps/web. Turbopack is treating the App Router app/ folder as the project root. app/ is the Next.js App Router routes directory — it should never be inferred as a project root.
  2. turbopack.root IS set in apps/web/next.config.mjs:
    import { fileURLToPath } from 'node:url'
    import { dirname } from 'node:path'
    const __dirname = dirname(fileURLToPath(import.meta.url))
    
    export default {
      turbopack: { root: __dirname },          // /…/apps/web (absolute)
      outputFileTracingRoot: __dirname,
    }
    Both turbopack.root and outputFileTracingRoot are pinned to absolute apps/web, but Turbopack ignores them and still reports apps/web/app as the project directory. The error message advises setting turbopack.root — which is already set.

Workaround

next dev --webpack works perfectly with the same structure:

cd apps/web && pnpm dev:webpack
✓ Ready in 263ms

So the bug is Turbopack-specific. Webpack mode honours the workspace correctly.

Provide environment information

- OS: macOS Darwin 25.3.0 (arm64)
- Node.js: v22.x
- pnpm: 9.15.0
- next: 16.2.3
- react: 19.2.4
- react-dom: 19.2.4
- Router: App Router

Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    TurbopackRelated to Turbopack with Next.js.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions