Skip to content

Conversation

@CarlyAThomas
Copy link
Contributor

Changes made:

  • Converted top-level Prisma imports to dynamic imports in getServerSideProps
  • Fixes 'PrismaClient is unable to be run in the browser' error
  • Affected pages: dashboard v1/v2, classes, admin pages

Pages updated:

  • pages/dashboard/v2/[id].js
  • pages/dashboard/v2/details/[id]/[studentEmail].js
  • pages/dashboard/[id].js
  • pages/classes/index.js
  • pages/admin/index.js
  • pages/admin/actions/[id].js

Why this fix is needed:
Next.js creates two bundles for each page - server (SSR) and client (navigation). Top-level imports are included in BOTH bundles. When users click Link components for client-side navigation, Next.js loads the client bundle which includes Prisma, causing 'PrismaClient is unable to be run in the browser' runtime errors.

This issue didn’t surface consistently because Prisma only causes errors when a page’s client bundle is loaded. Many navigation flows in this project triggered full page reloads, meaning the server bundle ran and Prisma stayed server-side.

The bug only appears when Next.js loads the client-side version of the page — which happens during:

  • navigation via (client routing)
  • production prefetching (Next.js automatically loads bundles in the background)

In this codebase, many dashboard and admin pages were usually reached via tags or manual URL navigation, which forced full reloads and hid the problem. As soon as users navigated with components or the app was tested in production mode, Next.js loaded the client bundle containing Prisma, causing the runtime error.

Dynamic importing Prisma inside getServerSideProps ensures Prisma is never included in client bundles, fixing the issue.

Checklist:

Not associated with an issue.

- Converted top-level Prisma imports to dynamic imports in getServerSideProps
- Fixes 'PrismaClient is unable to be run in the browser' error
- Affected pages: dashboard v1/v2, classes, admin pages

Pages updated:
- pages/dashboard/v2/[id].js
- pages/dashboard/v2/details/[id]/[studentEmail].js
- pages/dashboard/[id].js
- pages/classes/index.js
- pages/admin/index.js
- pages/admin/actions/[id].js

Why this fix is needed:
Next.js creates two bundles for each page - server (SSR) and client (navigation).
Top-level imports are included in BOTH bundles. When users click Link components
for client-side navigation, Next.js loads the client bundle which includes Prisma,
causing 'PrismaClient is unable to be run in the browser' runtime errors.

Dynamic imports inside getServerSideProps() ensure Prisma stays server-only,
as getServerSideProps is completely stripped from the client bundle.
@CarlyAThomas CarlyAThomas requested a review from a team as a code owner December 6, 2025 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant