Skip to content

fix(vite): ensure server sourcemap-preserver plugin actually runs - #35680

Merged
danielroe merged 7 commits into
nuxt:mainfrom
Mateleo:fix/24414-sourcemap-vlq-mappings
Jul 19, 2026
Merged

danielroe merged 7 commits into
nuxt:mainfrom
Mateleo:fix/24414-sourcemap-vlq-mappings

Conversation

@Mateleo

@Mateleo Mateleo commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #24414

📚 Description

Nitro strips all the line-to-line mapping data from production sourcemaps to save space, the issue is that too aggressive and nukes the entire mapping whenever the bundle includes any node_modules code, which Nuxt's SSR output always does.

So entry.mjs.map has an empty mappings field, so --enable-source-maps can't trace errors back to app.vue, it stops at entry.mjs.

What I did is tell Nitro when sourcemapMinify: false it keeps the full mappings. The chain entry.mjs → server.mjs.map → app.vue then resolves correctly.

@Mateleo
Mateleo requested a review from danielroe as a code owner July 19, 2026 10:48
@coderabbitai

This comment has been minimized.

@danielroe

Copy link
Copy Markdown
Member

is this definitely the issue? the linked issue is using nuxt v3 but main branch is on nitro v3 - would you confirm this also resolves things for the 4.x branch?

(if so, we'll keep this PR open to main, merge it in, and I'll cherry-pick it back)

@github-actions github-actions Bot added 5.x 🐛 bug Something isn't working as expected labels Jul 19, 2026
@danielroe danielroe changed the title fix(nitro-server): disable sourcemap minification fix(nitro): disable sourcemap minification Jul 19, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@35680

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@35680

nuxt

npm i https://pkg.pr.new/nuxt@35680

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@35680

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@35680

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@35680

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@35680

commit: db9f786

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
packages/vite/src/plugins/sourcemap-preserver.test.ts (2)

63-72: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Improve the mock to prevent regressions in array merging.

Currently, the nitro mock uses an empty rollupConfig, which masks the defu array merging bug present in the source code. If you fix the source code to append the plugin, you should consider adding a dummy plugin to this mock to ensure the test catches any future regressions where the array is accidentally overwritten rather than appended to.

💡 Proposed update to the test mock
     let buildBefore: (() => void) | undefined
     const nitro: NitroMock = {
-      options: { rollupConfig: {} },
+      options: { rollupConfig: { plugins: [{ name: 'existing-plugin' } as any] } },
       hooks: {
         hook (name: string, handler: () => void) {
           if (name === 'build:before') {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/vite/src/plugins/sourcemap-preserver.test.ts` around lines 63 - 72,
Update the nitro mock’s options.rollupConfig in the sourcemap preservation test
to include a dummy existing plugin array, ensuring the test verifies the source
logic appends the new plugin without overwriting existing entries. Keep the
existing hooks and build:before capture behavior unchanged.

77-80: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Locate the plugin safely.

If the rollupConfig mock is updated to include an existing plugin (or if Nitro natively injects plugins before this hook), the new plugin might not be at index 0. Use .find() instead of a hardcoded index to ensure the test remains robust.

💡 Proposed update
-    const nitroPlugin = nitro.options.rollupConfig.plugins?.[0]
+    const nitroPlugin = nitro.options.rollupConfig.plugins?.find(p => p && p.name === 'nuxt:sourcemap-import')
     expect(nitroPlugin).toBeDefined()
     if (!nitroPlugin) { return }
     expect(nitroPlugin.name).toBe('nuxt:sourcemap-import')
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/vite/src/plugins/sourcemap-preserver.test.ts` around lines 77 - 80,
Update the plugin lookup in the sourcemap-preservation test to search
nitro.options.rollupConfig.plugins with find() for the plugin named
"nuxt:sourcemap-import" instead of assuming it is at index 0. Keep the defined
assertion and subsequent name validation against the located plugin.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/vite/src/plugins/sourcemap-preserver.test.ts`:
- Around line 63-72: Update the nitro mock’s options.rollupConfig in the
sourcemap preservation test to include a dummy existing plugin array, ensuring
the test verifies the source logic appends the new plugin without overwriting
existing entries. Keep the existing hooks and build:before capture behavior
unchanged.
- Around line 77-80: Update the plugin lookup in the sourcemap-preservation test
to search nitro.options.rollupConfig.plugins with find() for the plugin named
"nuxt:sourcemap-import" instead of assuming it is at index 0. Keep the defined
assertion and subsequent name validation against the located plugin.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: eebb03a4-1457-41e4-b4ac-270c0487f5b4

📥 Commits

Reviewing files that changed from the base of the PR and between b9fb183 and a92997c.

📒 Files selected for processing (2)
  • packages/vite/src/plugins/sourcemap-preserver.test.ts
  • packages/vite/src/plugins/sourcemap-preserver.ts

@codspeed

codspeed Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 10.38%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 20 untouched benchmarks
⏩ 3 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ loadNuxt in the basic test fixture 419.4 ms 379.9 ms +10.38%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Mateleo:fix/24414-sourcemap-vlq-mappings (db9f786) with main (567bb93)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@Mateleo

Mateleo commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

@danielroe So yes I tested it against Nuxt 4.5 and Nuxt 5 with Nitro v3.

@Mateleo
Mateleo force-pushed the fix/24414-sourcemap-vlq-mappings branch from 2ae51c0 to cf01236 Compare July 19, 2026 13:56
@danielroe

Copy link
Copy Markdown
Member

I think sourcemapMinify is only needed for nitropack v2; in v3, it's only nuked if all the sourcemaps include node_modules (nitrojs/nitro#4031).

I think the right fix for that piece would be to open a PR in nitro to backport the same fix to v2.

(dropping that piece for now)

@danielroe danielroe changed the title fix(nitro): disable sourcemap minification fix(vite): ensure server sourcemap-preserver plugin actually runs Jul 19, 2026
@danielroe
danielroe enabled auto-merge July 19, 2026 23:12
@danielroe
danielroe added this pull request to the merge queue Jul 19, 2026
Merged via the queue into nuxt:main with commit a781ae4 Jul 19, 2026
30 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 19, 2026
2 of 5 tasks
danielroe added a commit that referenced this pull request Jul 20, 2026
…5680)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Roe <[email protected]>
(cherry picked from commit a781ae4)
@github-actions github-actions Bot mentioned this pull request Jul 20, 2026
danielroe added a commit that referenced this pull request Jul 20, 2026
…5680)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Roe <[email protected]>
(cherry picked from commit a781ae4)
danielroe added a commit that referenced this pull request Jul 23, 2026
…5680)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Roe <[email protected]>
@github-actions github-actions Bot mentioned this pull request Jul 23, 2026
danielroe added a commit that referenced this pull request Jul 23, 2026
…5680)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Roe <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x 🐛 bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack trace for production build with source map

2 participants