next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Turbopack standalone with pnpm GVS omits LMDB native dependency symlink despite outputFileTracingIncludes

Open r34son opened this issue 3 weeks ago • 2 comments

Link to the code that reproduces this issue

https://github.com/r34son/next-lmdb-gvs-repro

To Reproduce

  1. Use Node.js 22.23.4 and pnpm 12.18.0, then clone the linked reproduction.
  2. Run pnpm install --frozen-lockfile.
  3. Run pnpm repro.

The reproduction pins Next.js 16.5.0-canary.48, the latest published npm canary when tested on November 13, 2026. It uses only public packages and a small local consumer of [email protected]; LMDB is transitive. pnpm's global virtual store is placed outside the app in a sibling directory.

The script runs a Turbopack production build, copies .next/standalone to a new temporary location, verifies that every symlink resolves within that copy, starts the copied server, and requests ESM and CJS routes that write/read an LMDB database. It removes LMDB_PREBUILD, NODE_PATH, NODE_OPTIONS, and NEXT_TEST_NATIVE_DIR from the build/server environments. There are no dependency patches, additional source symlinks, or postbuild repairs.

Relevant configuration:

export default {
  output: 'standalone',
  outputFileTracingRoot: process.cwd(),
  turbopack: { root: process.cwd() },
  experimental: { turbopackDetectGlobalVirtualStore: true },
  serverExternalPackages: ['lmdb'],
  outputFileTracingIncludes: {
    '/**/*': [
      `./node_modules/.pnpm/node_modules/@lmdb/lmdb-${process.platform}-${process.arch}/**/*`,
    ],
  },
};

Current vs. Expected behavior

The build succeeds. The native package and binary are present in the standalone artifact, but its native dependency cannot be resolved from the relocated LMDB package. Both routes return HTTP 500:

All standalone symlinks resolve inside the copied artifact.
Native package included: true
Native binary included: true
LMDB dependency symlink included: false
Native package resolves from LMDB: MODULE_NOT_FOUND
/: HTTP 500; LMDB read/write passed: false
/cjs: HTTP 500; LMDB read/write passed: false

The runtime error is:

No native build was found for platform=darwin arch=arm64 runtime=node abi=127
attempted loading from:
  <standalone>/next_additional_roots/gvs/@/lmdb/2.9.4/<hash>/node_modules/lmdb
and package: @lmdb/lmdb-darwin-arm64

Expected: both routes return HTTP 200 and successfully write/read LMDB. The dependency symlink needed by LMDB should either be traced automatically or be expressible through standard outputFileTracingIncludes within the already registered GVS root, while retaining the app-level root.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.6.0: Fri Jul 31 19:18:48 PDT 2026; root:xnu-12377.161.14~5/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 22.23.4
  npm: 10.9.9
  Yarn: N/A
  pnpm: 12.18.0
Relevant Packages:
  next: 16.5.0-canary.48
  eslint-config-next: N/A
  react: 19.2.3
  react-dom: 19.2.3
  typescript: N/A
Next.js Config:
  output: standalone

This clean reproduction was executed on macOS arm64. Linux runtime behavior has not been verified here.

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

Module Resolution, Output, Turbopack

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

next build (local), Other (Deployed)

Additional context

There are two different symlinks to the platform package. The include matches the application's private hoist alias:

app/node_modules/.pnpm/node_modules/@lmdb/lmdb-darwin-arm64

That alias and all six platform-package files are present in the trace/standalone. However, this different existing dependency symlink is absent from the GVS trace metadata and copied artifact:

<GVS>/@/lmdb/2.9.4/<hash>/node_modules/@lmdb/lmdb-darwin-arm64

[email protected] creates a require function from the real LMDB package directory and resolves the platform package through that dependency link. The application's private hoist alias is not an ancestor lookup location for the relocated LMDB directory. The native binary itself is present; resolution fails before loading it.

With an app-level root, a leading ../ include that reaches the physical GVS location is rejected for leaving the root. An absolute owner-link path does not match, and lmdb/../@lmdb/... does not traverse to the physical parent after following the LMDB symlink. Additional roots currently enable dependency resolution, but the includes parser still starts from project_path and the glob walker descends through existing entries.

Source pointers: include parsing, glob normalization, include tracing.

Disclosure: this report and reproduction were prepared and submitted by Codex at the account owner's explicit request.

r34son avatar Nov 12 '26 23:11 r34son

Would you be open to a regression test for this? I’d compare standalone output under pnpm’s global virtual store with a regular pnpm install and check that the traced LMDB dependency remains resolvable from the deployed directory.

seragAhmed avatar Nov 13 '26 07:11 seragAhmed

Thanks for the clear reproduction in r34son/next-lmdb-gvs-repro.

Regarding the regression test proposed by @seragAhmed: yes, adding a regression test for this would be very valuable.

Here is what we observed inspecting the tracing pipeline:

  1. Why the native dependency fails to resolve: lmdb (via node-gyp-build-optional-packages) requires its platform package (@lmdb/lmdb-<platform>-<arch>) starting from its physical directory inside GVS (<GVS>/@/lmdb/<version>/<hash>/node_modules/@lmdb/...). While Turbopack standalone tracing successfully copies the GVS root into next_additional_roots/gvs and copies the native binary itself, the nested dependency symlink inside the GVS directory (.../node_modules/lmdb/node_modules/@lmdb/...) is not captured in NftAdditionalRoot.symlinks.

  2. Why outputFileTracingIncludes is blocked: In crates/next-core/src/next_config.rs (relativize_glob), user-defined include globs are strictly relative to project_path. Any pattern attempting to traverse up into the external GVS root with ../ is rejected as escaping the project root.

  3. Regression test approach: The test in test/production/standalone-mode/ should:

    • Configure a pnpm project with virtual-store-dir placed outside the app root.
    • Build with output: 'standalone' and experimental.turbopackDetectGlobalVirtualStore: true.
    • Assert that the copied standalone artifact preserves the nested dependency symlink in next_additional_roots/gvs and that requesting a route calling LMDB returns HTTP 200 without MODULE_NOT_FOUND.

Happy to collaborate on structuring this test or looking at how crates/next-api/src/nft.rs handles symlinks inside additional roots.

Pcmhacker-piro avatar Nov 14 '26 17:11 Pcmhacker-piro