Skip to the solution
MediumFrontend5 min read

Server Components and external packages — what does serverComponentsExternalPackages do?

1.1k views

The problem

Question presented to candidate: "A package with native binaries breaks when Next.js bundles it for Server Components. What does serverComponentsExternalPackages do, what is it called now, and when do you need it?"

What a strong answer should cover:

  • By default Next.js bundles the dependencies of Server Components and Route Handlers into the server output.
  • Some packages break when bundled: native addons, packages that read their own files at runtime, or packages with dynamic requires.
  • serverExternalPackages (renamed from experimental.serverComponentsExternalPackages in Next.js 15) tells Next.js to leave those packages unbundled and require them from node_modules at runtime.
  • Next.js already keeps a built-in list of such packages external (for example Prisma and sharp), so most apps never need to configure it.
  • The old experimental key is flagged as invalid, but Next.js still maps it to the new option and prints a warning.

Clarifying questions expected:

  • "What is the exact build or runtime error?" — module-not-found for a binary or a missing file points to bundling.
  • "Is the package already on the built-in list?" — then the problem is elsewhere.

Code / implementation expected: Yes — the config option and what changes in the build output.

  • rsc
  • serverExternal

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

5 min read · 8 sections

Read the code

Externalizing a native package
// next.config.ts
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
  serverExternalPackages: ["@acme/native-pdf"],
};
export default nextConfig;

// app/api/invoice/[id]/route.ts  (server code using the package)
import { renderPdf } from "@acme/native-pdf"; // required from node_modules at runtime
export async function GET(_req: Request, ctx: { params: Promise<{ id: string }> }) {
  const { id } = await ctx.params;
  const pdf = await renderPdf({ invoiceId: id });
  return new Response(pdf, { headers: { "content-type": "application/pdf" } });
}

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 26 of 129 in Next.js

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

All Next.js questions
Up nextMedium

What is proxy.ts in Next.js 16 and how do you migrate from middleware.ts?

Continue