Skip to content

fix: resolve vite via @nuxt/vite-builder under strict isolation#1283

Open
BellYun wants to merge 4 commits intonuxt:mainfrom
BellYun:fix/banner-null-guard
Open

fix: resolve vite via @nuxt/vite-builder under strict isolation#1283
BellYun wants to merge 4 commits intonuxt:mainfrom
BellYun:fix/banner-null-guard

Conversation

@BellYun
Copy link
Copy Markdown

@BellYun BellYun commented Apr 15, 2026

🔗 Linked issue

Refs nuxt/nuxt#34809 — this covers the CLI side. The devtools side is in nuxt/devtools#986.

📚 Description

Resolves vite via nuxt -> @nuxt/vite-builder -> vite instead of resolving it directly from cwd.
Under pnpm 11's enableGlobalVirtualStore, vite is not reachable from CWD or nuxt itself. However, since @nuxt/vite-builder declares vite as a direct dependency, the lookup now works correctly through that path.

  • Verified against a pnpm 11 globalVirtualStore repro.
  • Added a regression test.

@BellYun BellYun requested a review from danielroe as a code owner April 15, 2026 16:24
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 15, 2026

  • nuxt-cli-playground

    npm i https://pkg.pr.new/create-nuxt@1283
    
    npm i https://pkg.pr.new/nuxi@1283
    
    npm i https://pkg.pr.new/@nuxt/cli@1283
    

commit: 012d0f6

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 15, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing BellYun:fix/banner-null-guard (012d0f6) with main (e14ce27)

Open in CodSpeed

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 15, 2026

Warning

Rate limit exceeded

@BellYun has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 35 minutes and 22 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 35 minutes and 22 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cdfbaf27-5d3d-46c8-8308-b1d9d7daceca

📥 Commits

Reviewing files that changed from the base of the PR and between 788c248 and 012d0f6.

📒 Files selected for processing (3)
  • packages/nuxi/src/utils/banner.ts
  • packages/nuxi/src/utils/versions.ts
  • packages/nuxi/test/unit/utils/banner.spec.ts
📝 Walkthrough

Walkthrough

The PR updates package version resolution and builder detection. banner.ts: getBuilder now calls getPkgJSON(cwd, 'vite', { via: '@nuxt/vite-builder' }), uses null-safe checks (pkgJSON?.name?.includes('rolldown')) and falls back to 'unknown' for missing versions. versions.ts: getPkgVersion and getPkgJSON signatures gain an optional options?: { via?: string }; getPkgJSON builds a roots/searchFrom list and, when options.via resolves, adds that module path to the search order before looking for ${pkg}/package.json. A new Vitest unit test exercises getBuilder behavior with mocked getPkgJSON/getPkgVersion.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: fixing vite resolution via @nuxt/vite-builder under strict isolation, which matches the PR's core objective of handling pnpm 11's enableGlobalVirtualStore.
Description check ✅ Passed The description provides relevant context about the issue (pnpm 11 globalVirtualStore isolation), the solution (resolving vite via @nuxt/vite-builder), verification details, and mentions a regression test, all of which align with the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
packages/nuxi/test/unit/utils/banner.spec.ts (1)

13-16: Add coverage for the @nuxt/vite-builder alias path as well.

Both 'vite' and '@nuxt/vite-builder' hit the same switch branch; asserting both reduces regression risk.

🧪 Suggested test addition
 describe('getBuilder', () => {
   // regression for banner crash under pnpm globalVirtualStore
   // where vite is unreachable from cwd — getPkgJSON returns null
   it('does not throw when vite package.json cannot be resolved', () => {
     expect(() => getBuilder('/any', 'vite')).not.toThrow()
     expect(getBuilder('/any', 'vite')).toMatchObject({ name: 'Vite', version: '' })
+    expect(() => getBuilder('/any', '@nuxt/vite-builder')).not.toThrow()
+    expect(getBuilder('/any', '@nuxt/vite-builder')).toMatchObject({ name: 'Vite', version: '' })
   })
 })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nuxi/test/unit/utils/banner.spec.ts` around lines 13 - 16, Add a
second assertion in the existing test case to cover the alias path
'@nuxt/vite-builder' as well: call getBuilder('/any', '@nuxt/vite-builder') and
assert it does not throw and matches { name: 'Vite', version: '' }, mirroring
the existing assertions for getBuilder('/any', 'vite') in the same it block to
ensure both branches hitting the Vite case are covered.
packages/nuxi/src/utils/banner.ts (1)

21-21: Consider avoiding empty builder versions in returned metadata.

Line 21 can return version: '', which flows into packages/nuxi/src/commands/info.ts (Line 112) and renders as vite@. Consider either a non-empty sentinel or formatter-side omission of @ when version is empty.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nuxi/src/utils/banner.ts` at line 21, The builder metadata currently
returns version: '' when pkgJSON.version is missing, causing consumers to render
bare "vite@" strings; update the return object in banner.ts (the object with
name and version) to use a non-empty sentinel or omit the property when absent —
e.g., set version: pkgJSON?.version ?? undefined or only include version when
truthy so downstream code (the info rendering) can skip the "@".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/nuxi/src/utils/banner.ts`:
- Line 21: The builder metadata currently returns version: '' when
pkgJSON.version is missing, causing consumers to render bare "vite@" strings;
update the return object in banner.ts (the object with name and version) to use
a non-empty sentinel or omit the property when absent — e.g., set version:
pkgJSON?.version ?? undefined or only include version when truthy so downstream
code (the info rendering) can skip the "@".

In `@packages/nuxi/test/unit/utils/banner.spec.ts`:
- Around line 13-16: Add a second assertion in the existing test case to cover
the alias path '@nuxt/vite-builder' as well: call getBuilder('/any',
'@nuxt/vite-builder') and assert it does not throw and matches { name: 'Vite',
version: '' }, mirroring the existing assertions for getBuilder('/any', 'vite')
in the same it block to ensure both branches hitting the Vite case are covered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3e6e987f-ba2b-4d40-a0ae-4a760362b829

📥 Commits

Reviewing files that changed from the base of the PR and between e14ce27 and e4d695e.

📒 Files selected for processing (2)
  • packages/nuxi/src/utils/banner.ts
  • packages/nuxi/test/unit/utils/banner.spec.ts

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@e14ce27). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1283   +/-   ##
=======================================
  Coverage        ?   44.93%           
=======================================
  Files           ?       48           
  Lines           ?     1144           
  Branches        ?      326           
=======================================
  Hits            ?      514           
  Misses          ?      514           
  Partials        ?      116           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@danielroe
Copy link
Copy Markdown
Member

would you be able to go ahead and address the root cause? 🙏

I did some tinkering on the plane just now and I'm pretty sure we need to be able to resolve nuxt -> @nuxt/vite-builder -> vite instead of the current approach of directly trying to resolve vite.

@BellYun
Copy link
Copy Markdown
Author

BellYun commented Apr 15, 2026

would you be able to go ahead and address the root cause? 🙏

I did some tinkering on the plane just now and I'm pretty sure we need to be able to resolve nuxt -> @nuxt/vite-builder -> vite instead of the current approach of directly trying to resolve vite.

It was just a stopgap. I felt it was urgent to stop the crash first since it's a pretty bad experience for users. Already looking into the nuxt -> @nuxt/vite-builder -> vite path now.

I'll update this PR

@BellYun BellYun changed the title fix: guard banner against unresolved vite package fix: resolve vite via @nuxt/vite-builder under strict isolation Apr 15, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/nuxi/src/utils/versions.ts`:
- Around line 24-38: The search order currently pushes the resolved viaPath
after existing roots so resolution still prefers cwd/Nuxt; change the logic that
handles options?.via in the block that iterates roots so the resolved viaPath
(from resolveModulePath(options.via, { from, try: true })) is placed before the
generic roots — e.g. insert/unshift the viaPath into searchFrom (or build
searchFrom starting with viaPath) and then break — ensuring the via root is
prioritized when the subsequent loop over searchFrom resolves
`${pkg}/package.json`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 705b7b64-55c5-427a-bd67-cfe58fe7c4f9

📥 Commits

Reviewing files that changed from the base of the PR and between e4d695e and 788c248.

📒 Files selected for processing (3)
  • packages/nuxi/src/utils/banner.ts
  • packages/nuxi/src/utils/versions.ts
  • packages/nuxi/test/unit/utils/banner.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/nuxi/src/utils/banner.ts
  • packages/nuxi/test/unit/utils/banner.spec.ts

Comment thread packages/nuxi/src/utils/versions.ts
@BellYun BellYun force-pushed the fix/banner-null-guard branch 3 times, most recently from d5121fd to d1d01e3 Compare April 16, 2026 17:52
@BellYun BellYun force-pushed the fix/banner-null-guard branch from d1d01e3 to 012d0f6 Compare April 16, 2026 17:59
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.

3 participants