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

Next.Js Turbopack Fails To Load Native Node Addon In Pnpm Workspace

When using Next.js 16 with Turbopack (default bundler), importing a native Node addon (built with napi-rs) from a separate package in a pnpm workspace during server-side prerendering results in `TypeError: (void 0) is not a function`. The package is added to `serverExternalPackages`, but Turbopack still bundles or mishandles the native module, causing the imported binding to be undefined.

highConfidence 75%Next.jsAffected V16.0.0

Origin Analysis

Turbopack's module resolution for native addons in pnpm workspaces fails to properly externalize packages that contain `.node` files. The `serverExternalPackages` option is not honored for native modules, leading Turbopack to attempt bundling the native addon, which results in an undefined export when the module is loaded during server-side rendering.
1. Create a pnpm workspace with a `web-app` (Next.js 16) and a `rust-lib` package that contains a native addon built with napi-rs. 2. Build the native addon: `pnpm -C packages/rust-lib build`. 3. Add `rust-lib` to `serverExternalPackages` in `next.config.js`. 4. Run `pnpm -C packages/web-app build`. 5. Observe prerender error: `TypeError: (void 0) is not a function`.

Fixing Code Block

Edge Case Audit

Disabling Turbopack may reduce build performance and can cause differences in output between development and production if a future upgrade re-enables Turbopack. This workaround is temporary until the issue is fixed in Next.js core. After upgrading to a fixed version, remove the `experimental.turbopack: false` setting and verify that the native module loads correctly. Note that webpack may be deprecated in future Next.js releases, so long-term reliance on this fallback is not advisable.

Ecosystem Topology