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

NextExternalsPlugin Erroneously Externalizes TranspilePackages Dependencies In Next-Rspack Dev Mode On Windows + Pnpm

In Next.js 16.3.0 with Rspack enabled (NEXT_RSPACK=true) on Windows using pnpm, direct dependencies listed in transpilePackages are incorrectly externalized during development, leading to runtime errors such as 'No matching bindings found'. The issue is specific to the dev server and pages router; webpack dev and rspack production build work correctly.

highConfidence 85%Next.jsAffected V16.3.0

Origin Analysis

The Rspack port of NextExternalsPlugin lacks the same transpilePackages awareness as the webpack version, causing it to externalize modules that should be bundled, particularly when pnpm junctions on Windows alter real path resolution.
1. Clone https://github.com/helloworldcyj/rspack-next-externals-repro 2. Run `pnpm bootstrap` to generate vendor tarball and install dependencies 3. Run `pnpm repro:rspack` and open http://localhost:3100 4. Observe SSR error: 'FAILED: No matching bindings found for serviceIdentifier: Symbol(Config)' 5. For comparison, `pnpm repro:webpack` shows 'OK, answer = 42' and `pnpm build:rspack` works in production.

Fixing Code Block

Edge Case Audit

This minimal check may not cover all edge cases, such as scoped packages with subpaths (e.g., '@scope/pkg/sub' where only '@scope/pkg' is listed) or when transpilePackages entries are relative paths. Additionally, if the existing externals logic relies on other criteria (e.g., react-server conditions), skipping it entirely for transpiled packages might alter behavior. A more robust fix should use realpath resolution (e.g., fs.realpathSync) to compare against transpilePackages, ensuring compatibility with pnpm junctions. Test thoroughly with both webpack and rspack dev/production builds before deployment. Rollback by reverting this change if regressions appear.

Ecosystem Topology