Skip to content

fix: stub schema imports in SSR to prevent OOM#124

Merged
Norbiros merged 1 commit intoNorbiros:mainfrom
onmax:fix/ssr-schema-oom
Jan 29, 2026
Merged

fix: stub schema imports in SSR to prevent OOM#124
Norbiros merged 1 commit intoNorbiros:mainfrom
onmax:fix/ssr-schema-oom

Conversation

@onmax
Copy link
Contributor

@onmax onmax commented Jan 28, 2026

Closes #87

Summary

Large OpenAPI schemas (200KB+ generated types) cause OOM during SSR build because Vite parses the type files even though they're only used for TypeScript checking. This adds a Vite plugin to stub schema imports during SSR.

StackBlitz

Link Expected
Bug open-fetch-87 ❌ OOM or needs increased heap
Fix open-fetch-87-fix ✅ Build succeeds

CLI Reproduction

git clone --depth 1 --filter=blob:none --sparse https://github.com/onmax/repros.git
cd repros && git sparse-checkout set open-fetch-87
cd open-fetch-87 && pnpm i && pnpm build

Verify fix

git sparse-checkout add open-fetch-87-fix
cd ../open-fetch-87-fix && pnpm i && pnpm build

The -fix folder uses pnpm patch to apply the fix locally.

@nserver-dokploy

This comment has been minimized.

@onmax onmax force-pushed the fix/ssr-schema-oom branch 3 times, most recently from ba6f2df to ca7b117 Compare January 28, 2026 11:49
@onmax
Copy link
Contributor Author

onmax commented Jan 28, 2026

Did some profiling on this. The schema file isn't directly loaded during SSR - esbuild strips import type before Rollup sees them.

The real issue is memory accumulating across Nuxt's 3 build phases (client → server → nitro) without GC between them. GitHub Actions' ~2GB default isn't enough.


Alternative approach: generate .d.ts instead of .ts

- filename: `types/${moduleName}/schemas/${kebabCase(name)}.ts`
+ filename: `types/${moduleName}/schemas/${kebabCase(name)}.d.ts`

Vite/Rollup ignores .d.ts during bundling - only TypeScript sees them. No stub plugin needed.

Current PR works fine though, just documenting the alternative.

@onmax onmax force-pushed the fix/ssr-schema-oom branch from ca7b117 to 501b657 Compare January 28, 2026 13:27
@Norbiros
Copy link
Owner

Thanks for spotting this issue and opening the PR! I think the second solution you described (using .d.ts) is much simpler and more widely popular in the ecosystem. Could you use that approach instead?

@onmax onmax force-pushed the fix/ssr-schema-oom branch from 501b657 to 9c604e5 Compare January 29, 2026 19:33
@onmax
Copy link
Contributor Author

onmax commented Jan 29, 2026

Done! Switched to .d.ts approach - much cleaner 👍

@Norbiros Norbiros merged commit ba437f3 into Norbiros:main Jan 29, 2026
3 of 4 checks passed
@onmax onmax deleted the fix/ssr-schema-oom branch January 29, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optionally skipping schema based codegen on startup

2 participants