Skip to content

Debug ID injection skipped for main SPA bundle (HTML facade chunk) in Vite #839

@igoriuz

Description

@igoriuz

Environment

  • @sentry/vite-plugin: 4.6.2
  • @sentry/bundler-plugin-core: 4.6.2
  • vite: 7.2.7
  • unplugin: 1.0.1 (bundled with @sentry/bundler-plugin-core)
  • Framework: Vue 3 SPA

Steps to Reproduce

  1. Create a standard Vite SPA (Vue, React, etc.) with index.html as entry point
  2. Configure @sentry/vite-plugin in vite.config.ts
  3. Run vite build
  4. Inspect the generated main bundle dist/assets/index-xxx.js

Expected Result

The main bundle should contain the debug ID injection snippet:

e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="xxx",e._sentryDebugIdIdentifier="sentry-dbid-xxx"

Actual Result

The main bundle does not contain the debug ID injection snippet, while all other chunks (lazy-loaded routes, vendor chunks) are correctly injected.

Root cause: In @sentry/bundler-plugin-core, the shouldSkipCodeInjection function skips chunks where facadeModuleId ends with .html:

if (facadeModuleId && stripQueryAndHashFromPath(facadeModuleId).endsWith(".html")) {
  return true;
}

This was intended to skip MPA facade chunks that only contain import statements. However, in a Vite SPA, the main entry bundle also has facadeModuleId pointing to index.html, causing it to be incorrectly skipped:

// Main SPA bundle - SKIPPED (bug)
facadeModuleId: /path/to/project/index.html

// Other chunks - processed correctly  
facadeModuleId: /path/to/project/node_modules/some-lib/index.js

Impact:

window._sentryDebugIds only contains debug IDs for secondary chunks
Errors from the main bundle cannot be source-mapped
Stack traces show minified code
Workaround: Custom Vite plugin that runs before sentryVitePlugin to inject debug IDs into HTML facade chunks:

function sentryDebugIdHtmlFacadePlugin(): Plugin {
  return {
    name: 'sentry-debug-id-html-facade-fix',
    renderChunk(code, chunk) {
      const facadeModuleId = (chunk as any).facadeModuleId
      if (!facadeModuleId?.endsWith('.html')) return null
      // ... inject debug ID snippet
    }
  }
}

Suggested fix: Check if the chunk contains substantial code (not just imports) before skipping HTML facade chunks.

Metadata

Metadata

Assignees

Labels

No labels
No labels
No fields configured for issues without a type.

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions