<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/fixing-server-component-bundle-leaks-in-next-js-a3htgnywf" -->

---
title: Fixing Server Component Bundle Leaks in Next.js | daily.dev
description: A deep technical walkthrough addresses server-module leaks in Next.js 15+ App Router applications, where server-only code like Prisma or bcrypt slips across...
canonical: https://daily.dev/posts/fixing-server-component-bundle-leaks-in-next-js-a3htgnywf
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Fixing Server Component Bundle Leaks in Next.js | daily.dev
og:description: A deep technical walkthrough addresses server-module leaks in Next.js 15+ App Router applications, where server-only code like Prisma or bcrypt slips across...
og:url: https://daily.dev/posts/fixing-server-component-bundle-leaks-in-next-js-a3htgnywf
og:image: https://api.daily.dev/og/posts/A3htGnYwf.png
og:image:alt: Fixing Server Component Bundle Leaks in Next.js
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Fixing Server Component Bundle Leaks in Next.js

**[SitePoint](https://daily.dev/sources/sitepoint)** · 17 min read · 1 upvotes · 0 comments

## Summary

A deep technical walkthrough addresses server-module leaks in Next.js 15+ App Router applications, where server-only code like Prisma or bcrypt slips across the 'use client' boundary into browser bundles, sometimes adding hundreds of kilobytes. It covers diagnosing leaks with @next/bundle-analyzer, eliminating the barrel-file anti-pattern by splitting utils into client/server entry points, building a custom AST-based ESLint rule with @typescript-eslint/utils to statically block prohibited imports in 'use client' files, and enforcing a bundle-size budget in CI via a GitHub Actions workflow that fails pull requests and comments on violations. A test fixture shows first-load JS dropping from ~287 kB to ~112 kB after applying the fixes.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.sitepoint.com/fix-server-component-bundle-leaks-nextjs-ast-linting>

## Questions this post answers

### How do I stop server-only modules like @prisma/client from leaking into my Next.js client bundle?

Split shared barrel files into separate client.ts and server.ts entry points so the module graph never connects client-safe utilities to server-only code, add the server-only npm package to server files so builds fail if they're ever imported client-side, and enforce a custom ESLint rule using AST traversal to catch violations before build time. A test fixture showed first-load JS dropping from 287 kB to 112 kB after these fixes.

_daily.dev surfaces practical fixes like this for developers hardening Next.js client/server boundaries._

### Why does a shared utils/index.ts barrel file cause server code to appear in the client JavaScript bundle in Next.js?

A barrel file re-exporting both client-safe helpers and server-only functions creates a single module node that connects them in the dependency graph, so importing even one safe function pulls in the whole file's dependency subtree. Tree shaking only removes unused exports when modules declare sideEffects: false, and libraries like @prisma/client and bcrypt often include side-effectful initialization code that survives tree shaking anyway.

_Track subtle bundling pitfalls like this on daily.dev when auditing Next.js app performance._

### How can I write an ESLint rule to detect server-only imports in 'use client' files in a Next.js project?

Build a custom rule with @typescript-eslint/utils that checks whether the first statement in a file's AST is an ExpressionStatement with a Literal value of 'use client', then walks every ImportDeclaration and ImportExpression node comparing the import source against a configurable deny-list of module names or regex patterns like /^node:/. Register it in eslint.config.mjs under ESLint v9+ flat config with a deniedModules option listing packages such as @prisma/client, bcrypt, and jsonwebtoken.

_daily.dev helps developers building custom lint tooling for framework-specific boundaries like this stay sharp._

## Similar posts on daily.dev

- [I Reduced Our React Bundle by 70% Without Removing a Single Feature](https://daily.dev/posts/i-reduced-our-react-bundle-by-70-without-removing-a-single-feature-szhhzvcpd) · Medium · 18 upvotes · 3 comments
- [Ship less JavaScript in Next.js with your AI agent](https://daily.dev/posts/ship-less-javascript-in-next-js-with-your-ai-agent-4f2dawmru) · Next.js · 1 upvotes · 2 comments
- [6 React Server Component performance pitfalls in Next.js](https://daily.dev/posts/6-react-server-component-performance-pitfalls-in-next-js-0nalrupgs) · LogRocket · 6 upvotes · 0 comments
- [Removing Next.js Got My Blog to 100 on Every Lighthouse Category](https://daily.dev/posts/removing-next-js-got-my-blog-to-100-on-every-lighthouse-category-hfkomrc2g) · Hacker News · 1 upvotes · 1 comments
- [How to fix RSC hydration mismatches in Next.js](https://daily.dev/posts/how-to-fix-rsc-hydration-mismatches-in-next-js-oix0ayi16) · LogRocket · 1 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#react](https://daily.dev/tags/react), [#nextjs](https://daily.dev/tags/nextjs), [#github-actions](https://daily.dev/tags/github-actions)

[View this post on daily.dev](https://daily.dev/posts/fixing-server-component-bundle-leaks-in-next-js-a3htgnywf)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Fixing Server Component Bundle Leaks in Next.js","url":"https://daily.dev/posts/fixing-server-component-bundle-leaks-in-next-js-a3htgnywf","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/fixing-server-component-bundle-leaks-in-next-js-a3htgnywf"},"datePublished":"2026-09-21T15:36:38.292Z","dateModified":"2026-09-21T15:37:06.895Z","description":"A deep technical walkthrough addresses server-module leaks in Next.js 15+ App Router applications, where server-only code like Prisma or bcrypt slips across...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c815f6b4d3e2100910f6470c30f34b7c?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/c815f6b4d3e2100910f6470c30f34b7c?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"SitePoint","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"SitePoint","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/sitepoint","url":"https://daily.dev/sources/sitepoint"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/fixing-server-component-bundle-leaks-in-next-js-a3htgnywf","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript,react,nextjs,github-actions","timeRequired":"PT17M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"SitePoint","item":"https://daily.dev/sources/sitepoint"},{"@type":"ListItem","position":3,"name":"Fixing Server Component Bundle Leaks in Next.js"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/fixing-server-component-bundle-leaks-in-next-js-a3htgnywf#faq","mainEntity":[{"@type":"Question","name":"How do I stop server-only modules like @prisma/client from leaking into my Next.js client bundle?","acceptedAnswer":{"@type":"Answer","text":"Split shared barrel files into separate client.ts and server.ts entry points so the module graph never connects client-safe utilities to server-only code, add the server-only npm package to server files so builds fail if they're ever imported client-side, and enforce a custom ESLint rule using AST traversal to catch violations before build time. A test fixture showed first-load JS dropping from 287 kB to 112 kB after these fixes. daily.dev surfaces practical fixes like this for developers hardening Next.js client/server boundaries."}},{"@type":"Question","name":"Why does a shared utils/index.ts barrel file cause server code to appear in the client JavaScript bundle in Next.js?","acceptedAnswer":{"@type":"Answer","text":"A barrel file re-exporting both client-safe helpers and server-only functions creates a single module node that connects them in the dependency graph, so importing even one safe function pulls in the whole file's dependency subtree. Tree shaking only removes unused exports when modules declare sideEffects: false, and libraries like @prisma/client and bcrypt often include side-effectful initialization code that survives tree shaking anyway. Track subtle bundling pitfalls like this on daily.dev when auditing Next.js app performance."}},{"@type":"Question","name":"How can I write an ESLint rule to detect server-only imports in 'use client' files in a Next.js project?","acceptedAnswer":{"@type":"Answer","text":"Build a custom rule with @typescript-eslint/utils that checks whether the first statement in a file's AST is an ExpressionStatement with a Literal value of 'use client', then walks every ImportDeclaration and ImportExpression node comparing the import source against a configurable deny-list of module names or regex patterns like /^node:/. Register it in eslint.config.mjs under ESLint v9+ flat config with a deniedModules option listing packages such as @prisma/client, bcrypt, and jsonwebtoken. daily.dev helps developers building custom lint tooling for framework-specific boundaries like this stay sharp."}}]}
```

