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

Webpack Build Fails When PageExtensions Contains A Single Value

When pageExtensions is configured as a single-element array (e.g., ['tsx']), Next.js webpack build fails with resolution errors for app dir routes. The issue is caused by the loader receiving pageExtensions as a plain string due to query string serialization, and the string branch in next-app-loader missing the leading dot for extensions.

highConfidence 95%Next.jsAffected V16.3.0-Canary.78

Origin Analysis

In the webpack build, the next-app-loader receives its options serialized as a query string. A single-element array is serialized as a plain string (e.g., 'tsx'). The loader code handles the string type by wrapping it in an array but fails to prepend a dot, resulting in an extension list of ['tsx'] instead of ['.tsx']. This causes the resolver to look for files like pagetsx instead of page.tsx, leading to module resolution failure.
1. Clone the reproduction repository (https://github.com/KinjiKawaguchi/nextjs-single-page-extension-webpack-repro) and run pnpm install. 2. In next.config.js, set pageExtensions to a single value, e.g., ['tsx']. 3. Run pnpm build (which runs next build --webpack). 4. Observe build failure with errors like "Can't resolve private-next-app-dir/page". 5. Switch to a multi-element pageExtensions (e.g., ['tsx', 'ts']) and build again to see success.

Fixing Code Block

Edge Case Audit

This change aligns the string branch with the array branch, but should be tested with both single and multiple pageExtensions, including values that may already include a leading dot (e.g., ['.tsx']). The existing array branch already prepends a dot unconditionally, so this fix does not introduce new double-dot behavior but may expose pre-existing inconsistencies if users pass pre-dotted extensions. Rollback is straightforward: revert to the previous code (remove the dot in the string branch). No concurrency or threading issues are expected, but cross-platform and upgrade/rollback scenarios should be verified.

Ecosystem Topology