nextjs - ✅(Solved) Fix Turbopack rejects symlinked package.json pointing outside filesystem root [1 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#91896Fetched 2026-04-08 01:25:50
View on GitHub
Comments
3
Participants
3
Timeline
7
Reactions
1
Timeline (top)
commented ×3cross-referenced ×1issue_type_added ×1labeled ×1

PR fix notes

PR #92886: Support cross-root symlinks in Turbopack's filesystem layer, fixing module resolution failures in Bazel-sandboxed builds.

Description (problem / solution / changelog)

What?

Support cross-root symlinks in Turbopack's filesystem layer, fixing module resolution failures in Bazel-sandboxed builds.

Why?

Fixes https://github.com/vercel/next.js/issues/91896

In Bazel builds, rules_js assembles node_modules via symlink chains that ultimately point outside the Turbopack filesystem root. When read_link() encounters such a symlink, it returns LinkContent::Invalid and the entry is silently dropped — causing next build --turbopack to fail to resolve packages.

How?

  • Added classify_cross_root_symlink() — a centralized helper that falls back to OS-level metadata (via retry_blocking) when a symlink target is outside the fs root, classifying it as File/Directory/Other
  • Updated get_type(), realpath_with_links(), read_matches() (both fast and slow paths), and read_glob() to handle LinkContent::Invalid using this helper
  • Added resolve_symlink() calls in pages_structure.rs, app_structure.rs, require_context.rs, and import_meta_glob.rs so symlinked entries aren't silently dropped during directory iteration
  • Added cross_root: bool to RealPathResult so callers can distinguish cross-root paths from true canonical paths

Tests added

  • test_cross_root_symlink — relative symlink escaping the fs root, validates get_type and realpath_with_links
  • test_cross_root_symlink_absolute — absolute symlink (actual Bazel scenario), verifies the cross_root flag
  • test_subdir_symlinks_need_resolve_for_match — demonstrates resolve_symlink() is required for cross-root directory entries
  • test_pages_structure_finds_symlinked_pages_in_subdirs — end-to-end pages router discovery with cross-root symlinks
  • test_resolve_across_bazel_sandbox_symlinks — multi-hop symlink chain mimicking rules_js layout

Fixes #91896

Changed files

  • Cargo.lock (modified, +3/-0)
  • crates/next-core/Cargo.toml (modified, +5/-0)
  • crates/next-core/src/app_structure.rs (modified, +2/-2)
  • crates/next-core/src/pages_structure.rs (modified, +91/-0)
  • turbopack/crates/turbo-tasks-fs/src/lib.rs (modified, +346/-1)
  • turbopack/crates/turbo-tasks-fs/src/read_glob.rs (modified, +26/-11)
  • turbopack/crates/turbopack-core/src/resolve/mod.rs (modified, +88/-0)
  • turbopack/crates/turbopack-core/src/resolve/pattern.rs (modified, +106/-33)
  • turbopack/crates/turbopack-ecmascript/src/references/import_meta_glob.rs (modified, +1/-1)
  • turbopack/crates/turbopack-ecmascript/src/references/require_context.rs (modified, +2/-1)

Code Example

git clone https://github.com/jonaseriksson84/turbopack-symlink-repro
cd turbopack-symlink-repro
./setup.sh
cd build/app
npx next build            # Fails (Turbopack)
npx next build --webpack  # Succeeds

---

Operating System:
    Platform: linux
    Arch: x64
    Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
  Binaries:
    Node: 22.14.0
    npm: 10.9.2
  Relevant Packages:
    next: 16.1.6
    react: 19.2.4
    react-dom: 19.2.4
    typescript: 5.9.3
  Next.js Config:
    output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/jonaseriksson84/turbopack-symlink-repro

To Reproduce

git clone https://github.com/jonaseriksson84/turbopack-symlink-repro
cd turbopack-symlink-repro
./setup.sh
cd build/app
npx next build            # Fails (Turbopack)
npx next build --webpack  # Succeeds

Current vs. Expected behavior

When resolving a module in a sibling directory (shared-lib/util.js), Turbopack walks up looking for package.json for module type/side-effects detection. It finds build/package.json, which is a symlink to a file outside the filesystem root, and fails with:

Symlink package.json is invalid, it points out of the filesystem root

Expected: Turbopack should follow the symlink and read the target file, like webpack does. This pattern is standard in Bazel and similar build systems where source trees are assembled via symlinks.

Provide environment information

Operating System:
    Platform: linux
    Arch: x64
    Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
  Binaries:
    Node: 22.14.0
    npm: 10.9.2
  Relevant Packages:
    next: 16.1.6
    react: 19.2.4
    react-dom: 19.2.4
    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 build (local)

Additional context

Confirmed still reproduces on [email protected]. Also reproduces with next dev (on first page request).

We understand the filesystem root boundary likely exists as a security/sandboxing measure to prevent Turbopack from reading arbitrary files outside the project. However, symlinked package.json files pointing outside the build tree are the standard pattern in Bazel (and similar build systems), where an execroot is assembled entirely from symlinks. This makes Turbopack unusable in these environments, while webpack handles it fine.

Any ideas/suggestions on how to move forward or work around this issue?

extent analysis

Fix Plan

To resolve the issue with Turbopack failing to follow symlinks when resolving modules, we need to adjust the next.config.js file to specify a custom turbo configuration that allows symlinks.

Step-by-Step Solution:

  1. Create or edit next.config.js: Ensure you have a next.config.js file in the root of your project.
  2. Add custom Turbo configuration: Add the following code to your next.config.js to allow Turbopack to follow symlinks:
module.exports = {
  //... other configurations ...
  turbo: {
    symlinks: {
      enable: true,
    },
  },
}

However, since the issue seems to stem from a limitation in Turbopack's handling of symlinks that point outside the filesystem root, and given that the expected behavior is to follow symlinks like Webpack does, we might need to consider a workaround or a fix that involves either adjusting the project structure or contributing a fix to Turbopack itself.

Given the current state of the issue and the information provided, a direct configuration fix might not be feasible without adjusting how Turbopack handles symlinks internally. Thus, the solution might involve:

  • Contributing to Turbopack: If the community or maintainers agree that following symlinks in this manner is a desired feature, contributing a patch to Turbopack could be the long-term solution.
  • Adjusting Project Structure: Temporarily rearranging the project to avoid symlinks that point outside the build tree could be a workaround, though this might not be feasible depending on the project's requirements and build system constraints.

Verification

To verify that the fix worked, you would:

  • Run npx next build again after applying the suggested configuration or workaround.
  • If the issue was resolved, the build should succeed without errors related to symlinks.

Extra Tips

  • Monitor Turbopack Issues: Keep an eye on the Turbopack issue tracker for any updates or fixes related to symlink handling.
  • Community Engagement: Engage with the Next.js and Turbopack communities to discuss the best approach for handling symlinks in build processes, especially in environments like Bazel.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING