vercel / vercel/next.js

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

Open
#85,449 5 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Turbopack
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction repository, especially packages/rust-lib and packages/web-app. Run pnpm i, build rust-lib, then run the web-app build to reproduce the Turbopack failure, comparing the native addon loading path with the serverExternalPackages setting. Done means the web-app build succeeds and calls the rust-lib greet function.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, nodejs, rust
Domain
backend, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.