1

I am migrating my existing Next.js projects to a Turborepo monorepo.

The Next.js projects use the newest App Router, and have server-side routes and components which previously all successfully built outside of Turborepo, but now fail to build seemingly because they're seen as client code and they are loading server-side node modules (primarily firebase-admin). None of my dependencies in package.json have changed versions.

Here's an example page that should be regarded as server component. /src/app/example/[document_id]/page.js:

import { db } from "@/app/api/firebase-admin"
// import components

export default async function Page({ params: { document_id } }) {
    const docSnapshot = await db.collection('docs').doc(document_id).get();
    if (docSnapshot.exists) {
        const data = docSnapshot.data();
        return <Document {...data} />
    }
    return <NotFound />
}

The above code builds perfectly in a standalone Next.js project, but in Turborepo complains about things like Can't resolve 'fs' in @google/cloud/... which makes me think that it's trying to pack the server side modules for the client bundle.

Any help solving this issue is much appreciated.


EDIT: Wanted to mention here that my project is structured according to the standard, same as the example here

Hacktisch
  • 1,392
  • 15
  • 33

1 Answers1

1

From What I see in the turborepo code here You might need to have Turbo set up 1 level above your next project and let turborepo do its job of caching and bundling from there. As seen in line 6 It explicitly mentions that the build for the turbo repo depends on an existing nextjs build.

I hope this helps.

Yogeswar
  • 19
  • 3
  • Thanks for your reply! Unfortunately this is not the solution since my project already is structured that way... I'll add that information to my question – Hacktisch Jul 19 '23 at 13:23