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

Next Dev Hangs Forever When Module Request Exceeds V8 Regexp Stack Limit In Bundled Enhanced-Resolve

Next.js webpack dev server never resolves requests for modules whose identifiers exceed ~8.39M characters because the vendored enhanced-resolve uses a regex that overflows V8's RegExp stack, throwing RangeError and leaving the compilation promise permanently pending.

highConfidence 95%Next.jsAffected V15.5.18Affected V16.3.1-Canary.16

Origin Analysis

The bundled webpack in next/dist/compiled/webpack/bundle5.js contains an outdated enhanced-resolve whose parseIdentifier function runs the regex /^(#?(?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/ on every module request. For inputs above V8's RegExp stack limit (~8,388,572 chars), RegExp.exec throws RangeError: Maximum call stack size exceeded. The error is emitted as an unhandledRejection, not handled by the dev compiler, so the pending request never resolves.
1. git clone https://github.com/MuzajsArcin/nextjs-dev-hang-repro 2. cd nextjs-dev-hang-repro && npm install 3. node generate.mjs 8388573 # writes src/big.mjs with one 8,388,573-char data: URI 4. npm run dev 5. curl --max-time 60 http://localhost:3247/ -> never responds; dev server prints ○ Compiling / ... and RangeError: Maximum call stack size exceeded

Fixing Code Block

Edge Case Audit

This is a development-only workaround and should be removed once the bundled enhanced-resolve is updated. It only bypasses the regex for the specific pattern and inputs without null bytes; if a future request contains a null byte and is also extremely large, the original regex path may still overflow. Global monkey-patching RegExp.prototype.exec could theoretically affect other libraries that rely on exact regex execution semantics, but the scope is limited to the target source. To roll back, delete or comment out the patch block in next.config.js and restart the dev server.

Ecosystem Topology