Skip to content

fix(externals): externalize a package's own entry as its bare name - #4683

Merged
pi0 merged 3 commits into
nitrojs:mainfrom
hungateJoseph:fix/externals-root-export-subpath
Oct 13, 2026
Merged

pi0 merged 3 commits into
nitrojs:mainfrom
hungateJoseph:fix/externals-root-export-subpath

Conversation

@hungateJoseph

Copy link
Copy Markdown

🔗 Linked issue

Fixes #4678

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

When a traced dependency is imported by the absolute path of the file its "." export points at, guessSubpath looks the file up in the package's flattened exports and builds the external id with join(name, e.subpath). flattenExports gives the "." entry the subpath "./", so the id came out as dep/, and the output then failed at startup with ERR_PACKAGE_PATH_NOT_EXPORTED: Package subpath './' is not defined by "exports".

The "." export is the package itself, so that case now returns the bare package name. Named and wildcard subpaths are unchanged.

guessSubpath is exported so it can be tested on its own, alongside the other helpers this file already exports for tests. The new unit test builds a small package in a temp node_modules with a conditional "." export, a named subpath and a wildcard subpath. The "." cases fail on main with expected 'dep/' to be 'dep' and pass with this change, alongside the existing trace-deps tests.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

guessSubpath built the external id with join(name, e.subpath). The "."
export is flattened to the subpath "./", so a traced package imported by
the absolute path of its own entry became "dep/", and the output failed
at startup with ERR_PACKAGE_PATH_NOT_EXPORTED. Return the bare name for
that export and leave named and wildcard subpaths as they were.

Fixes nitrojs#4678
@hungateJoseph
hungateJoseph requested a review from pi0 as a code owner September 28, 2026 23:49
@vercel

vercel Bot commented Sep 28, 2026

Copy link
Copy Markdown

@hungateJoseph is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9d60be25-c223-442d-85ef-10723afcf371
📥 Commits

Reviewing files that changed from the base of the PR and between 6da30c9 and 5903df3.

⛔ Files ignored due to path filters (2)
  • test/fixture/node_modules/@fixture/nitro-root-export/index.mjs is excluded by !**/node_modules/**
  • test/fixture/node_modules/@fixture/nitro-root-export/package.json is excluded by !**/node_modules/**
📒 Files selected for processing (4)
  • src/build/plugins/externals.ts
  • test/fixture/nitro.config.ts
  • test/presets/vercel.test.ts
  • test/tests.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

📝 Walkthrough

The change returns the package name for a matched "." export instead of a trailing-slash subpath. A traced-package fixture and tests cover the route response and generated Vercel route output.

Changes: External package root export mapping

Layer / File(s) Summary
Root export mapping and route regression
src/build/plugins/externals.ts, test/fixture/nitro.config.ts, test/tests.ts, test/presets/vercel.test.ts
guessSubpath returns the package name for a matched "." export. The fixture adds a route for the traced package. Tests check the response, Vercel route configuration, and generated function symlink.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 5903d

The root export now maps to the package name, and the route test exercises the reported failure path. No concrete issue currently blocks merging.

Security architecture risk: ⚪ Minimal · up to 6da30

The change restores valid package-root imports without expanding permissions or introducing application endpoints. The added route is confined to test fixtures. No material security risk was identified in the reviewed change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The production effect is bounded to generated external identifiers for dependencies whose resolved file exactly matches an eligible root export. The inspected change adds no independently addressable tenant, service, credential, or privileged operation.

Trust Boundaries and Controls

  • observed — The helper still derives package identity from the resolved node_modules path, reads that package's exports, filters by allowed conditions, and requires an exact filesystem-target match before applying the changed root case. The comparison shows no removal of these checks or alteration of package-metadata authority.
Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title follows Conventional Commits syntax with the fix type, externals scope, and a clear summary of the root-export externalization fix.
Description check Passed The description directly explains the bug, its cause, the fix, linked issue, and test coverage. It is related to the changeset.
Linked Issues check Passed The changes satisfy issue #4678. guessSubpath now returns the package name for the "." export, so externalization produces the bare package name instead of dep/. Named and wildcard subpaths reta…
Out of Scope Changes check Passed The changes stay within issue #4678. The source fix and the fixture route, expected Vercel output, and runtime test provide regression coverage for package-root externalization. No unrelated product b…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR

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.

Replace the guessSubpath unit test, which used resolve conditions nitro never passes, with a fixture route that imports a traced package's conditional "." export by absolute path.
@pi0x pi0x added the v3 label Oct 7, 2026
# Conflicts:
#	test/presets/vercel.test.ts
@pkg-pr-new

pkg-pr-new Bot commented Oct 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 5903df3

@pi0
pi0 merged commit 44b35dd into nitrojs:main Oct 13, 2026
16 of 21 checks passed
@pi0x pi0x removed the v3 label Nov 10, 2026
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.

externals: absolute import of a traced package's "." export is rewritten to pkg/ (ERR_PACKAGE_PATH_NOT_EXPORTED)

3 participants