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