Skip to content

Next.js (Turbopack) fails to find/load native node addon compiled as a separate package in a (pnpm) workspace #85449

@daanboer

Description

@daanboer

Link to the code that reproduces this issue

https://github.com/daanboer/next-load-native-module

To Reproduce

  • Install dependencies.
pnpm i
  • Build the rust-lib package (needs a working rust installation).
pnpm -C packages/rust-lib build
  • Try to build the web-app package.
pnpm -C packages/web-app build

The web-app build process will throw the following error:

  Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
  TypeError: (void 0) is not a function
      at c (.next/server/chunks/ssr/[root-of-the-server]__9aa9e4ec._.js:1:392)
      at stringify (<anonymous>) {
    digest: '3868626329'
  }
  Export encountered an error on /page: /, exiting the build.

Current vs. Expected behavior

This is a followup of #71630, which highlights a similar issue when using webpack. As the default bundler switched to turbopack, I ran into this issue instead.

I expect the greet function declared in the rust-lib package to be called successfully. Instead I get the following error at build time:

  Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
  TypeError: (void 0) is not a function
      at c (.next/server/chunks/ssr/[root-of-the-server]__9aa9e4ec._.js:1:392)
      at stringify (<anonymous>) {
    digest: '3868626329'
  }
  Export encountered an error on /page: /, exiting the build.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1-NixOS SMP PREEMPT_DYNAMIC Thu Sep 11 15:21:47 UTC 2025
  Available memory (MB): 64179
  Available CPU cores: 48
Binaries:
  Node: 22.20.0
  npm: N/A
  Yarn: N/A
  pnpm: 10.19.0
Relevant Packages:
  next: 16.0.0
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local)

Additional context

The native node addon is built using napi. I have added rust-lib to serverExternalPackages, but that does not solve the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    TurbopackRelated to Turbopack with Next.js.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions