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.jsServer Actionsnext buildAffected 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

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state