nextjs - ✅(Solved) Fix Turbopack ignores turbopack.root in pnpm monorepo, infers App Router `app/` as project directory [1 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#92540Fetched 2026-04-09 07:49:53
View on GitHub
Comments
1
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
commented ×1labeled ×1

Error Message

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.

Fix Action

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.

PR fix notes

PR #35268: fix(web): include dify-ui workspace package in docker install filter

Description (problem / solution / changelog)

Summary

  • fix the web Docker install filter so the image build installs the new @langgenius/dify-ui workspace package together with its dependencies
  • keep clsx and tailwind-merge owned by @langgenius/dify-ui instead of adding them back to web
  • revert the temporary next.config.ts monorepo overrides because they were not required for this failure

Problem

Commit af7d5e60b47503a0c5c3751fa783d63654644a21 introduced the new workspace package @langgenius/dify-ui and moved cn to that package.

The web Docker image only installed:

  • pnpm install --filter ./web... --frozen-lockfile

That filter covered the web workspace, but it did not prepare dependency resolution for @langgenius/dify-ui in the clean Docker build environment. During next build, Turbopack resolved ./packages/dify-ui/src/cn.ts and then failed on:

  • Can't resolve 'clsx'
  • Can't resolve 'tailwind-merge'

Fix

Update web/Dockerfile to install both workspaces during the image build:

  • pnpm install --filter ./web... --filter @langgenius/dify-ui... --frozen-lockfile

This keeps the dependency ownership in the workspace package where it belongs and makes the Docker build environment match the new workspace layout.

Why not next.config.ts

I verified in a clean local reproduction that reverting the PR's turbopack.root and outputFileTracingRoot changes still allows the build to pass once the Docker install filter includes @langgenius/dify-ui.

So the failing Docker build was an install-scope problem, not a Next config problem.

Test plan

  • Reproduce the failure in a clean local workspace with the original Docker install filter
  • Verify npx pnpm install --filter ./web... --filter @langgenius/dify-ui... --frozen-lockfile
  • Verify cd web && npx pnpm build in a clean local workspace after the filter change
  • CI Docker build passes

Changed files

  • web/Dockerfile (modified, +2/-3)

Code Example

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.

---

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,
   }

---

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

---

- 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
RAW_BUFFERClick to expand / collapse

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

  • Minimal repro: 7 source files, no extra deps. Plain pnpm workspace + one Next App Router app. No nested workspaces, no file: deps, no custom resolver.
  • The repo's apps/web/node_modules/next resolves correctly via the standard pnpm symlink (../../../node_modules/.pnpm/[email protected].../next).
  • This was a regression for us when upgrading from [email protected] (no such issue) to 16.2.3.
  • Possibly related but distinct: #92534 (Windows pnpm "Next.js package not found" — runtime panic, not workspace inference) and #85057 (closed; sibling file: package, not pnpm workspace).

extent analysis

TL;DR

The most likely fix is to adjust the turbopack.root configuration to correctly point to the project root, potentially by using a relative path or ensuring the absolute path is correctly resolved.

Guidance

  • Verify that the __dirname variable in next.config.mjs is correctly resolving to the apps/web directory, as this is used to set turbopack.root.
  • Consider using a relative path for turbopack.root instead of an absolute one, to ensure it is correctly resolved by Turbopack.
  • Check if there are any differences in how Turbopack resolves paths compared to Webpack, as the issue only occurs with Turbopack.
  • Review the pnpm workspace configuration to ensure that the next package is correctly resolved and accessible from the apps/web directory.

Example

No specific code example is provided, as the issue is related to the configuration and resolution of paths in Turbopack.

Notes

The issue appears to be specific to Turbopack and may be related to how it resolves paths and infers the project root. The fact that Webpack mode works correctly suggests that the issue is not with the overall project configuration, but rather with how Turbopack is handling the turbopack.root configuration.

Recommendation

Apply a workaround by adjusting the turbopack.root configuration, as the issue is specific to Turbopack and a fix may not be available in the current version. Consider using a relative path or ensuring the absolute path is correctly resolved to point to the project root.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING