-
Hi, I’m running into a bundle size issue in my Next.js 15 app. Here’s my setup: For each page (example // /app/page.tsx
import { Landing } from "@/components/pages";
export default function LandingPage() {
return <Landing />;
} And inside export * from "./artist-detail";
export * from "./auth";
export * from "./landing";
export * from "./list";
export * from "./list-detail";
export * from "./onboarding";
export * from "./player";
export * from "./q";
export * from "./search";
export * from "./see-all-artist";
export * from "./select-artist";
export * from "./songs"; The ProblemWhen I do this, the build output looks like this (bundle sizes get really large, most routes around 432 kB):
But if I don’t use
My Question
Thanks! Additional information"next": "15.5.0"
"react": "19.1.1" ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Quick follow up, are you using Webpack/Turbopack? |
Beta Was this translation helpful? Give feedback.
-
One of the answers I got on reddit: |
Beta Was this translation helpful? Give feedback.
Right, so the question we need to answer is, why do barrel-files not make tree shaking just work?
Barrel files tend to be problematic because bundlers often can't prove that dropping some code is ok, because it was side-effect free. Mostly we see this problem with icon libraries, or libraries that pack a lot of utilities, for that Next.js has. way to rewrite the imports for you, https://nextjs.org/docs/app/api-reference/config/next-config-js/optimizePackageImports, but it might be negatively be impact by side-effects.
Here's a thread that discusses barrel files: webpack/webpack#16863 (comment)
If you search around, you'll find many that say barrel files are anti-pattern.
I think there's a…