Dev.to
7/25/2026

One Icon Import Nearly Took Down My Entire WSL2 Dev Environment
Short summary
A dynamic icon import in a Next.js 16 + Turbopack project pulled ~9,000 modules into the dev compiler graph, exhausting WSL2's memory ceiling and freezing the entire environment. The production build passed fine because it compiles once and exits, while next dev keeps the full graph resident. Adding the offending packages to experimental.optimizePackageImports in next.config.ts cut steady-state RSS from ~3.6GB to ~1.87GB — a 48% baseline reduction.
- •Dynamic/barrel imports pull entire package graphs into Turbopack's dev compiler, not just the items you use
- •next build passing doesn't predict next dev memory behavior — dev keeps the graph resident permanently
- •optimizePackageImports in next.config.ts rewrites barrel imports to direct file paths, cutting RSS ~48%
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



