next.js
ab5db580 - Don't blame the Pages Router for next/headers imported through a Client Component (#100087)

Commit
25 days ago
Don't blame the Pages Router for next/headers imported through a Client Component (#100087) ## Summary When a Client Component imports a module outside `app/` (e.g. `lib/shared.js`) that depends on `next/headers`, the error said the API was being used "in the Pages Router", even in apps with no `pages` directory. The RSC transform picked the message by whether the file is inside `appDir`, but a module outside `app/` can still be part of the App Router graph. The transform now takes an explicit `isAppRouter` option. Webpack sets it from the bundle layer, and Turbopack from whether the context has an `appDir` (only the Pages Router context passes none). App Router graphs get the Client Component message; Pages Router files still get the Pages Router one. ## Verification - `cargo test -p next-custom-transforms` (no existing fixture outputs changed) - `pnpm test-dev-turbo` / `pnpm test-dev-webpack` on `test/development/acceptance/server-component-compiler-errors-in-pages.test.ts` and `test/e2e/app-dir/next-after-pages/index.test.ts`, which still assert the Pages Router message for Pages Router files <!-- NEXT_JS_LLM --> --------- Co-authored-by: vercel-gh-bot-2[bot] <282331341+vercel-gh-bot-2[bot]@users.noreply.github.com>
Author
Parents
Loading