-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Environment
@sentry/vite-plugin: 4.6.2@sentry/bundler-plugin-core: 4.6.2vite: 7.2.7unplugin: 1.0.1 (bundled with @sentry/bundler-plugin-core)- Framework: Vue 3 SPA
Steps to Reproduce
- Create a standard Vite SPA (Vue, React, etc.) with
index.htmlas entry point - Configure
@sentry/vite-plugininvite.config.ts - Run
vite build - 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
Projects
Status