Skip to content

fix(assets): emit bundled scripts into nitro public output - #995

Open
danielroe wants to merge 1 commit into
mainfrom
fix-script-asset-emission
Open

danielroe wants to merge 1 commit into
mainfrom
fix-script-asset-emission

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

📚 Description

on Nuxt 5, a clean production build with a bundled registry script renders a preload and script tag for a file that isn't in the output.

this is because the bundled files are written to .nuxt/cache/scripts in build:done, and that directory is registered as a Nitro public asset dir.

on Nuxt 4 the Nitro build itself runs in build:done hook, which means the files are on disk in time, but in Nuxt 5 the Nitro build (and its public asset copy) happens inside the Vite build, before any build:done hook, so if it's a clean build, it will just copy an empty directory.

this PR writes the rendered scripts straight into the Nitro public output from nitro:build:public-assets, which Nuxt calls right after the public asset copy on both Nuxt 4 and 5.

this probably should also be backported to 1.x

@danielroe
danielroe requested a review from harlan-zw November 29, 2026 13:17
@vercel

vercel Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated
scripts-playground Error Error Nov 29, 2026 1:17pm UTC

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Nov 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/scripts-devtools@995
npm i https://pkg.pr.new/@nuxt/scripts@995

commit: 6707619

@github-actions

Copy link
Copy Markdown

📦 Package Size

⚠️ 2 size metrics grew

📚 22 runtime dependencies (no change)

Package output Gzipped Δ
@nuxt/scripts · export . 27 kB → 27 kB 🔴 +106 B (+0.4%)
@nuxt/scripts · published payload 244 kB → 244 kB 🔴 +106 B (+0.0%)
All tracked output (25)
Package output Gzipped Raw
@nuxt/scripts-cli · runtime dependencies 72 kB 355 kB ✅
@nuxt/scripts-cli · dependency magicast 72 kB 355 kB ✅
@nuxt/scripts-cli · export . 3.4 kB 12 kB ✅
@nuxt/scripts-cli · published payload 3.4 kB 12 kB ✅
@nuxt/scripts · runtime dependencies 543 kB 2.40 MB ✅
@nuxt/scripts · dependency @oxc-project/types 0 B 0 B ✅
@nuxt/scripts · dependency @vueuse/core 178 kB 720 kB ✅
@nuxt/scripts · dependency @vueuse/shared 39 kB 152 kB ✅
@nuxt/scripts · dependency lru-cache 141 kB 623 kB ✅
@nuxt/scripts · dependency semver 25 kB 72 kB ✅
@nuxt/scripts · dependency sirv 8.8 kB 21 kB ✅
@nuxt/scripts · dependency unstorage 70 kB 225 kB ✅
@nuxt/scripts · dependency valibot 82 kB 590 kB ✅
@nuxt/scripts · dist/runtime 126 kB 337 kB ✅
@nuxt/scripts · export . 27 kB 101 kB 🔴
@nuxt/scripts · export ./registry 288 B 449 B ✅
@nuxt/scripts · export ./stats 12 kB 97 kB ✅
@nuxt/scripts · export ./types-source 50 kB 259 kB ✅
@nuxt/scripts · published payload 244 kB 883 kB 🔴
@nuxt/scripts · app runtime 176 B 658 B ✅
@nuxt/scripts · components runtime 3.6 kB 8.5 kB ✅
@nuxt/scripts · composables runtime 10 kB 29 kB ✅
@nuxt/scripts · registry runtime 52 kB 140 kB ✅
@nuxt/scripts · server runtime 40 kB 108 kB ✅
@nuxt/scripts · utils runtime 3.5 kB 8.6 kB ✅
Runtime dependencies (22)
Package Dependency Requested Resolved Cost
@nuxt/scripts-cli magicast ^0.5.5 0.5.5 📦 72 kB gzip
@nuxt/scripts-cli pathe ^2.0.3 2.0.3 ♻️ free via Nuxt 4.7.0
@nuxt/scripts @nuxt/kit ^4.7.0 4.7.0 ♻️ free via Nuxt 4.7.0
@nuxt/scripts @oxc-project/types ^0.153.0 0.153.0 📦 0 B gzip
@nuxt/scripts @vueuse/core ^15.0.0 15.0.0 📦 178 kB gzip
@nuxt/scripts @vueuse/shared ^15.0.0 15.0.0 📦 39 kB gzip
@nuxt/scripts consola ^3.4.2 3.4.2 ♻️ free via Nuxt 4.7.0
@nuxt/scripts defu ^6.1.7 6.1.7 ♻️ free via Nuxt 4.7.0
@nuxt/scripts lru-cache ^11.5.3 11.5.3 📦 141 kB gzip
@nuxt/scripts magic-string ^1.4.3 1.4.3 ♻️ free via Nuxt 4.7.0
@nuxt/scripts ofetch ^1.5.1 1.5.1 ♻️ free via Nuxt 4.7.0
@nuxt/scripts ohash ^2.0.12 2.0.12 ♻️ free via Nuxt 4.7.0
@nuxt/scripts oxc-walker ^1.1.1 1.1.1 ♻️ free via Nuxt 4.7.0
@nuxt/scripts pathe ^2.0.3 2.0.3 ♻️ free via Nuxt 4.7.0
@nuxt/scripts semver ^7.8.5 7.8.5 📦 25 kB gzip
@nuxt/scripts sirv ^3.0.2 3.0.2 📦 8.8 kB gzip
@nuxt/scripts std-env ^4.3.0 4.3.0 ♻️ free via Nuxt 4.7.0
@nuxt/scripts ufo ^1.6.4 1.6.4 ♻️ free via Nuxt 4.7.0
@nuxt/scripts ultrahtml ^1.7.0 1.7.0 ♻️ free via Nuxt 4.7.0
@nuxt/scripts unplugin ^3.4.0 3.4.0 ♻️ free via Nuxt 4.7.0
@nuxt/scripts unstorage ^1.17.5 1.17.5 📦 70 kB gzip
@nuxt/scripts valibot ^1.5.0 1.5.0 📦 82 kB gzip

Baseline: main_@_f08c676d___2026-11-25 · gzip is the comparison metric · changes below 16 B gzip are ignored

@coderabbitai

coderabbitai Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The nitro:build:public-assets hook creates the public output directory and writes rendered scripts that have filenames and no errors. The unit test invokes the hook and verifies that only the named, successful script is written.

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

Merge Risk: Minimal · up to 67076

This change writes bundled registry scripts into the public output after the asset copy, which fixes missing script files in clean Nuxt 5 production builds. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: bundled scripts are now emitted into the Nitro public output. It matches the summarised change in packages/script/src/assets.ts, which writes rendered scripts from the…
Description check Passed The description states the problem (clean Nuxt 5 production builds miss a bundled registry script), its cause (scripts written to .nuxt/cache/scripts in build:done, after the Nitro public asset copy),…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: bundled scripts are now emitted into the Nitro public output. It matches the summarised change in packages/script/src/assets.ts, which writes rendered scripts from the nitro:build:public-assets hook. The title follows the conventional commit form and is specific enough for a reviewer scanning history.

Full details: Description check

Explanation

The description states the problem (clean Nuxt 5 production builds miss a bundled registry script), its cause (scripts written to .nuxt/cache/scripts in build:done, after the Nitro public asset copy), and the fix (writing rendered scripts from nitro:build:public-assets). This matches the raw summary of assets.ts and the test changes. The linked issue section is left as an unfilled template comment, but the description is clearly related to the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a2442dd8-8b8c-4b75-9fb4-829728fc64ae
Commits

Reviewing files that changed from the base of the PR and between f08c676 and 6707619.

Files selected for processing: 2

  • packages/script/src/assets.ts
  • test/unit/public-assets.test.ts

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

@harlan-zw

Copy link
Copy Markdown
Collaborator

🟠 Approval needed · outside contributor

Thanks for the pull request. Automated review and repair of 6707619 wait for Harlan.

Harlan adds the harlan-agent-review label to start them.

Harlan Agent Kit automated status, not Harlan's · AI policy

This branch had an error being deployed

1 failed deployment
Preview — 67076194 Deployed Nov 29, 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.

2 participants