AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Next.Js 16 Dev Server Consumes 2GB OS Memory On Startup With React 19

When starting the Next.js development server (pnpm dev) on a large project (FastGPT), the process uses approximately 2GB of OS memory immediately, causing potential performance issues on machines with limited RAM.

mediumConfidence 60%Next.jsAffected V16.x

Origin Analysis

The excessive memory usage is likely caused by the default Turbopack bundler in Next.js 16, which may have inefficient caching or module graph building for large projects, especially when combined with React 19's advanced features that increase retained metadata.
1. Clone the FastGPT repository (https://github.com/labring/FastGPT) on Windows 11 with pnpm 10. 2. Run `pnpm dev`. 3. Observe the OS memory usage; it reaches ~2GB during startup.

Fixing Code Block

Modify the `scripts` section in `package.json` to force the use of webpack instead of Turbopack: ```json "scripts": { "dev": "next dev --webpack" } ``` Additionally, clear the existing build cache by deleting the `.next` folder before restarting: `rm -rf .next` (or `rmdir /s .next` on Windows).
Forcing the dev server to use webpack can reduce memory usage for some projects because webpack's memory management is more mature in certain scenarios. This is a temporary workaround until Turbopack's memory issues are resolved upstream.

Edge Case Audit

This workaround may not guarantee lower memory usage for all projects and could increase dev server startup time. It also switches away from Turbopack-specific optimizations, potentially causing differences in development behavior. To rollback, revert the script change and run the default `next dev`. Monitor memory and consider upgrading to a patched Next.js version when available.

Ecosystem Topology