Skip to content

fix(externals): keep per-version ids for traced externals imported from bundled code - #4740

Merged
pi0 merged 1 commit into
mainfrom
fix/ext-versions
Oct 7, 2026
Merged

pi0 merged 1 commit into
mainfrom
fix/ext-versions

Conversation

@pi0x

@pi0x pi0x commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Resolves #4731

When bundled modules import the same traced external but resolve different versions of it (e.g. app → bcrypt@1, bundled workspace package → nested bcrypt@2), the externals plugin returned the bare specifier for both. The bundler merged the imports, so in production both sides silently got whichever version was hoisted.

Changes

  • Upgrade nf3 to ^0.4.1, which returns the traced output layout and hoists the version that resolves from rootDir (feat: return traced output layout and hoist rootDir-resolvable version unjs/nf3#76).
  • At resolveId, each traced external gets a unique placeholder id per resolved file, so imports of different versions are no longer merged.
  • At renderChunk, each placeholder is rendered from the nf3 layout:
    • bare specifier when that version is the one linked at node_modules/<name> (output unchanged in the common case)
    • otherwise a relative path to its traced copy (node_modules/.nf3/<name>@<version>/...)
    • bare specifier as a fallback when the layout has no entry for the file (same as previous behavior)
  • Regression test: test/fixture/node_modules/nitro-bundled-dep (bundled) imports its own nested @fixture/[email protected], while the app imports the root 2.0.0.

Example output (rolldown):

import { version } from "bcrypt";
import { version as compositionVersion } from "../node_modules/.nf3/[email protected]/index.js";

🤖 Generated with AI assistant

…om bundled code

Traced externals resolved to different versions were emitted with the same bare specifier, so bundled importers silently shared one version. Use the nf3 output layout to import non-hoisted versions by path. Resolves #4731.
@pi0x
pi0x requested a review from pi0 as a code owner October 7, 2026 04:51
@vercel

vercel Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nitro.build Ready Ready Preview Oct 7, 2026 4:52am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6e8d5073-bc24-4f57-bff7-00ee50d993a6
📥 Commits

Reviewing files that changed from the base of the PR and between 2641042 and 0fbe797.

⛔ Files ignored due to path filters (5)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • test/fixture/node_modules/nitro-bundled-dep/index.mjs is excluded by !**/node_modules/**
  • test/fixture/node_modules/nitro-bundled-dep/node_modules/@fixture/nitro-lib/index.mjs is excluded by !**/node_modules/**
  • test/fixture/node_modules/nitro-bundled-dep/node_modules/@fixture/nitro-lib/package.json is excluded by !**/node_modules/**
  • test/fixture/node_modules/nitro-bundled-dep/package.json is excluded by !**/node_modules/**
📒 Files selected for processing (4)
  • package.json
  • src/build/plugins/externals.ts
  • test/fixture/server/routes/modules.ts
  • test/tests.ts
 ______________________________
< Bugs bunny, at your service. >
 ------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednf3@​0.4.0 ⏵ 0.4.1100 +1100100 +195 +6100

View full report

@pkg-pr-new

pkg-pr-new Bot commented Oct 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4740

commit: 0fbe797

@pi0
pi0 merged commit e530e9b into main Oct 7, 2026
14 of 15 checks passed
@pi0
pi0 deleted the fix/ext-versions branch October 7, 2026 04:54

This branch was successfully deployed

1 active deployment
Preview — 0fbe7979 Deployed Oct 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bundled modules silently share one version of an external dependency that they resolve to different versions

2 participants