For Workers & Pages, what is the name of the domain?
What is the error number?
Failed: generating Pages Functions failed.
What is the error message?
Generated Pages Functions bundle size (31525333) is over the limit of 25.0 MiB
What is the issue or error you’re encountering
I don’t understand (confused) where the 31MB size comes from. Locally it’s 3MB
(du -sh .svelte-kit/cloudflare
command)
What steps have you taken to resolve the issue?
- Moved 3 legal pages from Paraglide JS locale (2 locales in total) that being stored in JSON to a DB. Barely change bundle size based on Cloudflare build logs. Additionally reduced length of each message.
- Changed some import from static to dynamic.
- Eliminated all
import * as...
except those inshadcn-svelte
components. - Removed unused deps. Before removing final bundle locally was
5MB
- Read similar issues.
What are the steps to reproduce the issue?
Full build log
npm warn
and other build warnings are not related to the main issue and can be ignored.
Note: I’ve removed vars from logs that is in wrangler.toml
2025-06-03T11:13:01.074638Z Cloning repository...
2025-06-03T11:13:02.298229Z Using v2 root directory strategy
2025-06-03T11:13:02.318785Z Success: Finished cloning repository files
2025-06-03T11:13:03.985263Z Checking for configuration in a Wrangler configuration file (BETA)
2025-06-03T11:13:03.986318Z
2025-06-03T11:13:03.98744Z Found wrangler.toml file. Reading build configuration...
2025-06-03T11:13:03.995598Z pages_build_output_dir: .svelte-kit/cloudflare
2025-06-03T11:13:03.995774Z Build environment variables:
2025-06-03T11:13:05.098303Z Successfully read wrangler.toml file.
2025-06-03T11:13:05.167246Z Detected the following tools from environment: [email protected], [email protected]
2025-06-03T11:13:05.167938Z Installing project dependencies: npm clean-install --progress=false
2025-06-03T11:13:07.075539Z npm warn ERESOLVE overriding peer dependency
2025-06-03T11:13:07.076553Z npm warn While resolving: @melt-ui/[email protected]
2025-06-03T11:13:07.076769Z npm warn Found: [email protected]
2025-06-03T11:13:07.076888Z npm warn node_modules/svelte
2025-06-03T11:13:07.077018Z npm warn dev svelte@"^5.0.0" from the root project
2025-06-03T11:13:07.077097Z npm warn 14 more (@lucide/svelte, @sveltejs/kit, ...)
2025-06-03T11:13:21.594697Z
2025-06-03T11:13:21.595665Z > [email protected] prepare
2025-06-03T11:13:21.601031Z > husky
2025-06-03T11:13:21.603061Z
2025-06-03T11:13:21.76177Z
2025-06-03T11:13:21.761991Z added 751 packages, and audited 752 packages in 16s
2025-06-03T11:13:21.762349Z
2025-06-03T11:13:21.7625Z 144 packages are looking for funding
2025-06-03T11:13:21.762577Z run `npm fund` for details
2025-06-03T11:13:21.778202Z
2025-06-03T11:13:21.778405Z 7 vulnerabilities (6 low, 1 moderate)
2025-06-03T11:13:21.778538Z
2025-06-03T11:13:21.778667Z To address issues that do not require attention, run:
2025-06-03T11:13:21.778763Z npm audit fix
2025-06-03T11:13:21.77886Z
2025-06-03T11:13:21.778947Z To address all issues possible (including breaking changes), run:
2025-06-03T11:13:21.779044Z npm audit fix --force
2025-06-03T11:13:21.77915Z
2025-06-03T11:13:21.779248Z Some issues need review, and may require choosing
2025-06-03T11:13:21.779343Z a different dependency.
2025-06-03T11:13:21.779639Z
2025-06-03T11:13:21.779993Z Run `npm audit` for details.
2025-06-03T11:13:21.811222Z Executing user command: npm run build
2025-06-03T11:13:22.196445Z
2025-06-03T11:13:22.196734Z > [email protected] build
2025-06-03T11:13:22.196898Z > svelte-kit sync && vite build
2025-06-03T11:13:22.197029Z
2025-06-03T11:13:26.06351Z e[36mvite v6.2.4 e[32mbuilding SSR bundle for production...e[36me[39m
2025-06-03T11:13:27.626464Z [success] [paraglide-js] Compilation complete (message-modules)
2025-06-03T11:13:27.650574Z transforming...
2025-06-03T11:13:37.252102Z e[32m✓e[39m 4915 modules transformed.
2025-06-03T11:13:37.309708Z e[33mGenerated an empty chunk: "entries/pages/dashboard/_page.server.ts".e[39m
2025-06-03T11:13:37.894096Z rendering chunks...
2025-06-03T11:13:42.849151Z e[33m[plugin vite:reporter]
2025-06-03T11:13:42.84958Z (!) /opt/buildhome/repo/src/lib/services/paginationCache.ts is dynamically imported by /opt/buildhome/repo/src/routes/dashboard/+page.svelte, /opt/buildhome/repo/src/routes/dashboard/+page.svelte, /opt/buildhome/repo/src/routes/dashboard/+page.svelte but also statically imported by /opt/buildhome/repo/src/routes/dashboard/components/dashboard/paginationHelper.ts, /opt/buildhome/repo/src/routes/dashboard/components/user-nav/profile-dialog.helper.ts, dynamic import will not move module into another chunk.
2025-06-03T11:13:42.84975Z e[39m
2025-06-03T11:13:42.851248Z
2025-06-03T11:13:42.851453Z 🔍 === CLOUDFLARE BUNDLE SIZE ANALYSIS ===
2025-06-03T11:13:42.851583Z 📊 Total Bundle Size: 0.693 MB (726747 bytes)
2025-06-03T11:13:42.85171Z
2025-06-03T11:13:42.851827Z 📦 Top 15 Largest Files:
2025-06-03T11:13:42.85195Z 1. _app/immutable/assets/_layout.D_Xst7Nz.css (asset): 0.117 MB (16.9%)
2025-06-03T11:13:42.852071Z 2. entries/pages/dashboard/_page.svelte.js (chunk): 0.097 MB (14.0%)
2025-06-03T11:13:42.852171Z 3. chunks/_index.js (chunk): 0.096 MB (13.9%)
2025-06-03T11:13:42.852254Z 4. index.js (chunk): 0.045 MB (6.5%)
2025-06-03T11:13:42.852351Z 5. chunks/product_error_barcode_required_default.js (chunk): 0.029 MB (4.2%)
2025-06-03T11:13:42.852437Z 6. chunks/apiErrors.js (chunk): 0.028 MB (4.0%)
2025-06-03T11:13:42.852533Z 7. chunks/index3.js (chunk): 0.021 MB (3.0%)
2025-06-03T11:13:42.852698Z 8. chunks/index2.js (chunk): 0.015 MB (2.1%)
2025-06-03T11:13:42.852844Z 9. chunks/pricing_tier_extra_cta.js (chunk): 0.013 MB (1.8%)
2025-06-03T11:13:42.852951Z 10. entries/pages/blog/_slug_/_page.svelte.js (chunk): 0.011 MB (1.6%)
2025-06-03T11:13:42.85305Z 11. entries/pages/_layout.svelte.js (chunk): 0.010 MB (1.5%)
2025-06-03T11:13:42.853151Z 12. entries/pages/blog/authors/_authorSlug_/_page.svelte.js (chunk): 0.009 MB (1.3%)
2025-06-03T11:13:42.853236Z 13. entries/pages/impact/_page.svelte.js (chunk): 0.009 MB (1.2%)
2025-06-03T11:13:42.853316Z 14. _app/immutable/assets/_page.D0MNMJ81.css (asset): 0.007 MB (1.0%)
2025-06-03T11:13:42.853397Z 15. chunks/internal.js (chunk): 0.007 MB (1.0%)
2025-06-03T11:13:42.853493Z
2025-06-03T11:13:42.853573Z 📋 Size by File Type:
2025-06-03T11:13:42.853674Z js: 0.560 MB (101 files)
2025-06-03T11:13:42.853755Z css: 0.133 MB (7 files)
2025-06-03T11:13:42.853847Z === END ANALYSIS ===
2025-06-03T11:13:42.853929Z
2025-06-03T11:13:45.916734Z Supabase Admin Client initialized (server-side only).
2025-06-03T11:13:48.69365Z e[36mvite v6.2.4 e[32mbuilding for production...e[36me[39m
2025-06-03T11:13:49.768334Z [success] [paraglide-js] Compilation complete (message-modules)
2025-06-03T11:13:49.773447Z transforming...
2025-06-03T11:14:00.696683Z e[32m✓e[39m 4998 modules transformed.
2025-06-03T11:14:01.705253Z rendering chunks...
2025-06-03T11:14:10.999941Z e[33m[plugin vite:reporter]
2025-06-03T11:14:11.000253Z (!) /opt/buildhome/repo/src/lib/services/paginationCache.ts is dynamically imported by /opt/buildhome/repo/src/routes/dashboard/+page.svelte, /opt/buildhome/repo/src/routes/dashboard/+page.svelte, /opt/buildhome/repo/src/routes/dashboard/+page.svelte but also statically imported by /opt/buildhome/repo/src/routes/dashboard/components/dashboard/paginationHelper.ts, /opt/buildhome/repo/src/routes/dashboard/components/user-nav/profile-dialog.helper.ts, dynamic import will not move module into another chunk.
2025-06-03T11:14:11.000384Z e[39m
2025-06-03T11:14:11.004993Z
2025-06-03T11:14:11.005162Z 🔍 === CLOUDFLARE BUNDLE SIZE ANALYSIS ===
2025-06-03T11:14:11.005373Z 📊 Total Bundle Size: 1.057 MB (1108144 bytes)
2025-06-03T11:14:11.005577Z
2025-06-03T11:14:11.006144Z 📦 Top 15 Largest Files:
2025-06-03T11:14:11.006256Z 1. _app/immutable/nodes/11.CXMuofwL.js (chunk): 0.192 MB (18.2%)
2025-06-03T11:14:11.006328Z 2. _app/immutable/chunks/CDT69dzY.js (chunk): 0.153 MB (14.4%)
2025-06-03T11:14:11.007329Z 3. _app/immutable/chunks/C2A-ZPmO.js (chunk): 0.119 MB (11.3%)
2025-06-03T11:14:11.007434Z 4. _app/immutable/assets/0.N5M46T-T.css (asset): 0.118 MB (11.1%)
2025-06-03T11:14:11.007499Z 5. _app/immutable/chunks/C5KCokmL.js (chunk): 0.111 MB (10.5%)
2025-06-03T11:14:11.007557Z 6. _app/immutable/chunks/BnJl_fYU.js (chunk): 0.052 MB (4.9%)
2025-06-03T11:14:11.007672Z 7. _app/immutable/chunks/CVAELrZE.js (chunk): 0.031 MB (3.0%)
2025-06-03T11:14:11.007746Z 8. _app/immutable/nodes/0.Bc7nYieL.js (chunk): 0.031 MB (2.9%)
2025-06-03T11:14:11.007809Z 9. _app/immutable/chunks/Dp9b9llf.js (chunk): 0.018 MB (1.7%)
2025-06-03T11:14:11.007866Z 10. _app/immutable/nodes/21.A9utjGzu.js (chunk): 0.017 MB (1.6%)
2025-06-03T11:14:11.007925Z 11. _app/immutable/chunks/f9v1rqXC.js (chunk): 0.015 MB (1.4%)
2025-06-03T11:14:11.008015Z 12. _app/immutable/nodes/5.CIdsP5OU.js (chunk): 0.013 MB (1.2%)
2025-06-03T11:14:11.008091Z 13. _app/immutable/nodes/18.DDevzpi1.js (chunk): 0.011 MB (1.0%)
2025-06-03T11:14:11.00815Z 14. _app/immutable/nodes/6.BjgmnKJu.js (chunk): 0.010 MB (0.9%)
2025-06-03T11:14:11.008207Z 15. _app/immutable/nodes/2.9ip2g1OI.js (chunk): 0.009 MB (0.9%)
2025-06-03T11:14:11.008288Z
2025-06-03T11:14:11.008356Z 📋 Size by File Type:
2025-06-03T11:14:11.008424Z js: 0.923 MB (64 files)
2025-06-03T11:14:11.008481Z css: 0.134 MB (7 files)
2025-06-03T11:14:11.008551Z json: 0.000 MB (1 files)
2025-06-03T11:14:11.008622Z === END ANALYSIS ===
2025-06-03T11:14:11.008678Z
2025-06-03T11:14:14.554388Z computing gzip size...
2025-06-03T11:14:14.579046Z e[2m.svelte-kit/output/client/e[22me[32m_app/version.json e[39me[1me[2m 0.03 kBe[22me[1me[22me[2m │ gzip: 0.05 kBe[22m
2025-06-03T11:14:14.579345Z e[2m.svelte-kit/output/client/e[22me[32m.vite/manifest.json e[39me[1me[2m 22.57 kBe[22me[1me[22me[2m │ gzip: 2.47 kBe[22m
...............
2025-06-03T11:14:14.589269Z e[2m.svelte-kit/output/client/e[22me[36m_app/immutable/chunks/CDT69dzY.js e[39me[1me[2m160.10 kBe[22me[1me[22me[2m │ gzip: 40.40 kBe[22m
2025-06-03T11:14:14.589389Z e[2m.svelte-kit/output/client/e[22me[36m_app/immutable/nodes/11.CXMuofwL.js e[39me[1me[2m202.39 kBe[22me[1me[22me[2m │ gzip: 54.83 kBe[22m
2025-06-03T11:14:14.589584Z e[32m✓ built in 25.89se[39m
2025-06-03T11:14:15.580626Z Supabase Admin Client initialized (server-side only).
2025-06-03T11:14:21.142473Z e[2m.svelte-kit/output/server/e[22me[32m.vite/manifest.json e[39me[1me[2m 27.09 kBe[22me[1me[22m
2025-06-03T11:14:21.142709Z e[2m.svelte-kit/output/server/e[22me[35m_app/immutable/assets/_page.BeqMqOvt.css e[39me[1me[2m 0.35 kBe[22me[1me[22m
..............
2025-06-03T11:14:21.151915Z e[2m.svelte-kit/output/server/e[22me[36mentries/pages/dashboard/_page.svelte.js e[39me[1me[2m101.82 kBe[22me[1me[22m
2025-06-03T11:14:21.151973Z e[2m.svelte-kit/output/server/e[22me[36mchunks/_index.js e[39me[1me[2m110.78 kBe[22me[1me[22m
2025-06-03T11:14:21.152033Z e[32m✓ built in 55.05se[39m
2025-06-03T11:14:21.152096Z
2025-06-03T11:14:21.152179Z Run npm run preview to preview your production build locally.
2025-06-03T11:14:21.155047Z
2025-06-03T11:14:21.155186Z > Using @sveltejs/adapter-cloudflare
2025-06-03T11:14:21.18117Z ✔ done
2025-06-03T11:14:21.468688Z Finished
2025-06-03T11:14:22.382814Z Checking for configuration in a Wrangler configuration file (BETA)
2025-06-03T11:14:22.383489Z
2025-06-03T11:14:22.384122Z Found wrangler.toml file. Reading build configuration...
2025-06-03T11:14:22.391422Z pages_build_output_dir: .svelte-kit/cloudflare
2025-06-03T11:14:22.391596Z Build environment variables:
2025-06-03T11:14:23.495171Z Successfully read wrangler.toml file.
2025-06-03T11:14:23.495939Z Found _worker.js in output directory. Uploading.
2025-06-03T11:14:23.502399Z ⛅️ wrangler 3.101.0
2025-06-03T11:14:23.502693Z -------------------
2025-06-03T11:14:26.911106Z ✨ Compiled Worker successfully
2025-06-03T11:14:28.336034Z Generated Pages Functions bundle size (31524831) is over the limit of 25.0 MiB
2025-06-03T11:14:29.571489Z Failed: generating Pages Functions failed. Check the logs above for more information. If this continues for an unknown reason, contact support: https://cfl.re/3WgEyrH
Stack
Sveltekit and the following:
"dependencies": {
"@aws-sdk/client-s3": "^3.787.0",
"@aws-sdk/s3-request-presigner": "^3.787.0",
"@google/genai": "^0.10.0",
"@notionhq/client": "^3.0.0",
"@supabase/auth-helpers-sveltekit": "^0.13.0",
"@supabase/ssr": "^0.6.1",
"@supabase/supabase-js": "^2.49.4",
"clsx": "^2.1.1",
"googleapis": "^148.0.0",
"lucide-svelte": "^0.509.0",
"prismjs": "^1.30.0",
"resend": "^4.5.1",
"tailwind-merge": "^3.2.0",
"tailwind-variants": "^1.0.0",
"tailwindcss-animate": "^1.0.7"
}
Related files (wrangler, vite.config, svelte.config)
# wrangler.toml
compatibility_date = "2025-04-28"
compatibility_flags = [ "nodejs_compat", "nodejs_als" ]
# Pages specific configuration
pages_build_output_dir = ".svelte-kit/cloudflare"
[vars]
# keys here...
// svelte.config.js
import adapter from '@sveltejs/adapter-cloudflare';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: vitePreprocess(),
kit: {
adapter: adapter({
// Optional: Cloudflare Pages specific options can go here if needed later
// routes: {
// include: ['/*'],
// exclude: ['<all>'] // Default, usually fine
// },
// Explicitly list private environment variables
// This ensures the adapter knows about them during the build process.
env: {
privatePrefix: '',
private: [
'GEMINI_API_KEY',
'R2_ACCOUNT_ID',
'R2_ACCESS_KEY_ID',
'R2_SECRET_ACCESS_KEY',
'SUPABASE_SERVICE_ROLE_KEY',
'GITHUB_PAT',
'GITHUB_OWNER',
'GITHUB_REPO',
'GOOGLE_AUTH_CLIENT_ID',
'GOOGLE_AUTH_CLIENT_SECRET',
'GOOGLE_REDIRECT_URI',
'RESEND_API_KEY',
'NOTION_AUTH_CLIENT_ID',
'NOTION_AUTH_CLIENT_SECRET'
]
}
}),
env: {
dir: '.'
},
alias: {
$lib: './src/lib'
}
}
};
export default config;
// vite.config.mjs
import { visualizer } from 'rollup-plugin-visualizer';
import tailwindcss from '@tailwindcss/vite';
import { svelteTesting } from '@testing-library/svelte/vite';
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { paraglideVitePlugin } from '@inlang/paraglide-js';
// Custom plugin for Cloudflare build analysis
const cloudflareBundleAnalyzer = () => ({
name: 'cloudflare-bundle-analyzer',
generateBundle(options, bundle) {
// Always run analysis and use console.error to ensure visibility in Cloudflare logs
console.error('\n🔍 === CLOUDFLARE BUNDLE SIZE ANALYSIS ===');
const chunks = Object.entries(bundle)
.map(([name, chunk]) => {
let size = 0;
if (chunk.type === 'chunk') {
size = chunk.code ? chunk.code.length : 0;
} else if (chunk.type === 'asset') {
size = chunk.source ?
(typeof chunk.source === 'string' ? chunk.source.length : chunk.source.byteLength)
: 0;
}
return {
name,
type: chunk.type,
size,
sizeMB: (size / 1024 / 1024).toFixed(3)
};
})
.sort((a, b) => b.size - a.size);
const totalSize = chunks.reduce((sum, chunk) => sum + chunk.size, 0);
const totalMB = (totalSize / 1024 / 1024).toFixed(3);
console.error(`📊 Total Bundle Size: ${totalMB} MB (${totalSize} bytes)`);
console.error('\n📦 Top 15 Largest Files:');
chunks.slice(0, 15).forEach((chunk, index) => {
const percentage = ((chunk.size / totalSize) * 100).toFixed(1);
console.error(`${index + 1}. ${chunk.name} (${chunk.type}): ${chunk.sizeMB} MB (${percentage}%)`);
});
// Show chunks over 1MB
const largechunks = chunks.filter(chunk => chunk.size > 1024 * 1024);
if (largechunks.length > 0) {
console.error('\n⚠️ Files over 1MB:');
largechunks.forEach(chunk => {
console.error(` • ${chunk.name}: ${chunk.sizeMB} MB`);
});
}
// Analyze by file type
const byType = chunks.reduce((acc, chunk) => {
const ext = chunk.name.split('.').pop() || 'unknown';
if (!acc[ext]) acc[ext] = { count: 0, size: 0 };
acc[ext].count++;
acc[ext].size += chunk.size;
return acc;
}, {});
console.error('\n📋 Size by File Type:');
Object.entries(byType)
.sort(([,a], [,b]) => b.size - a.size)
.forEach(([ext, data]) => {
const sizeMB = (data.size / 1024 / 1024).toFixed(3);
console.error(` ${ext}: ${sizeMB} MB (${data.count} files)`);
});
console.error('=== END ANALYSIS ===\n');
// Warn if approaching Cloudflare limit
if (totalSize > 20 * 1024 * 1024) {
console.error(`⚠️ WARNING: Bundle size (${totalMB} MB) is approaching Cloudflare's 25MB limit!`);
}
}
});
export default defineConfig({
plugins: [
tailwindcss(),
sveltekit(),
paraglideVitePlugin({
project: './project.inlang',
outdir: './src/lib/paraglide',
strategy: ['cookie', 'url', 'baseLocale'],
disableAsyncLocalStorage: true
}),
// Add our custom analyzer
cloudflareBundleAnalyzer(),
],
build: {
minify: 'terser',
terserOptions: {
compress: {
pure_funcs: ['console.log', 'console.warn', 'assert'],
drop_debugger: true,
passes: 3,
},
format: {
comments: false,
},
},
rollupOptions: {
plugins: [
visualizer({
filename: './dist/stats.html',
open: true,
gzipSize: true,
brotliSize: true,
}),
],
}
},
ssr: {
noExternal: ['@inlang/paraglide-js']
},
test: {
// Workspace configuration remains the same
workspace: [
{
extends: './vite.config.mts',
plugins: [svelteTesting()],
test: {
name: 'client',
environment: 'jsdom',
clearMocks: true,
include: ['src/**/*.svelte.{test,spec}.{js,ts}'],
exclude: ['src/lib/server/**'],
setupFiles: [
'./vitest-setup-client.ts',
'./tests/setup/msw-setup.ts'
]
}
},
{
extends: './vite.config.mts',
test: {
name: 'server',
environment: 'node',
include: ['src/**/*.{test,spec}.{js,ts}'],
exclude: ['src/**/*.svelte.{test,spec}.{js,ts}']
}
}
]
}
});
Notes:
- Paraglide messages (2 json locales combined) is just
100kb
- a few images being bundled. Less than
1MB
- all media (images) pulls from Supbase/R2 buckets.
Main questions
- Any suggestion what to look for?
- How to trace what takes the most space? Because local size != Cloudflare build size.
- What am I missing?
Thank you for your time