Is there any way to share Next.js pages across multiple apps in a Turborepo? #86968
Unanswered
girishcx07
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I am exploring whether it is possible to share Next.js pages across multiple apps inside a Turborepo.
Context
My repository structure looks like this:
Both
app1andapp2have almost identical modules and functionality. To avoid duplication, I created acommon-uipackage and tried moving reusable pages and components into these packages.Issues I Encountered
However, when I attempted to import Next.js pages or modules from these shared packages, I hit several limitations:
Next.js APIs (cookies, headers, server-only modules) cannot be used inside shared packages.
I received tracing and runtime errors such as: “Cookies can only be used inside a Next.js App Router environment”.
Server Components and Client Components behave inconsistently when located in external workspaces.
Next.js seems to isolate each app at the project root, so external packages lose access to Next.js internals.
The Turborepo was originally created using a ShadCN template, which heavily couples the structure to a single app.
The repository feels heavier than expected and difficult to extend for multi-app sharing.
Additional Context: TSUP Exploration
I also started exploring TSUP to optimise and bundle my shared packages.
However, I am not sure whether TSUP is the appropriate choice in this scenario:
At this stage, I am unsure where TSUP fits into a multi-app Next.js monorepo, especially when the goal is to reuse App Router components.
What I Want to Achieve
app1andapp2.Questions
Is it currently possible to share Next.js pages or App Router modules (layouts, routes, server components) across apps in a Turborepo?
Are there recommended patterns for:
How should TSUP be used (or avoided) in a monorepo where shared packages need to integrate tightly with Next.js?
If anyone has an example repository with such a setup, could you share guidance or best practices?
If recreating the repo from scratch is easier, I am open to step-by-step help.
Any suggestions or sample structures would be greatly appreciated.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions