I'm facing build failures in Next.js due to the public folder's large bundle size being included. #68160
Replies: 2 comments 1 reply
-
Step 1: Update your next.config.ts to this file import type { NextConfig } from 'next'; const nextConfig: NextConfig = { productionBrowserSourceMaps: false, output: 'standalone', }; export default nextConfig; Step 2: install this package npm install --save-dev rimraf Step 3: replace you build script in package json "build": "next build && rimraf .next/cache", |
Beta Was this translation helpful? Give feedback.
-
You're running into a common issue with Next.js when deploying serverless functions (e.g. on Vercel, Netlify, AWS Lambda) using output: 'standalone' mode — Next.js includes more files than necessary, including large assets from public/, which can bloat your bundle and exceed deployment limits. Let’s walk through why this happens, what your workaround does, and how to implement a cleaner, robust fix. Why Is public/ Being Bundled?
By default:
I hope this helps you find a resolution if not already. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
We are experiencing an issue where our builds are consistently failing due to the bundle size being too large. After looking into it, I found that the public folder, which contains many images, is being included in our Function’s bundle, leading to this problem.
The main issue is that Next.js is bundling our entire root directory, including the public folder, which results in unnecessary files being included in the standalone output. This significantly increases the bundle size and causes build failures.
I am seeking guidance on why Next.js is bundling the entire root directory and if there is a better way to prevent the public folder from being included in the bundle. While I have a temporary workaround, I am looking for a more robust and permanent solution to this issue.
To temporarily resolve this, I have added the following configuration to our next.config.js:
Additional information
No response
Example
https://github.com/FilecoinFoundationWeb/filecoin-foundation
Beta Was this translation helpful? Give feedback.
All reactions