You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 29, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 29, 2026. It is now read-only.
sentryVitePlugin creates unnecessary JS modules for each index page #829
// vite.config.jsimport{sentryVitePlugin}from"@sentry/vite-plugin";import{defineConfig}from"vite";exportdefaultdefineConfig({appType: "mpa",build: {rollupOptions: {input: ["index.html","page1.html","page2.html"],},},plugins: [// Enable this to reproduce the bug:// sentryVitePlugin({}),],});
In my example, index.html has no scripts, and page1.html and page2.html both load the same shared module:
The sentryVitePlugin should add metadata to generated modules (like shared-module-[hash].js in the example), but should not rework the import graph, create new modules, or add script tags to pages that didn't have them in the first place.
Actual Result
A unique module is generated for every html page in rollup.options.input. Pages that had been sharing modules will instead load a page-specific module that imports the shared code. Pages that didn't contain any scripts will now have one.
These unnecessary scripts slow page loading and interfere with caching.
This probably also affects Vite single page apps; the extra chunk the plugin creates is just less obvious for a SPA with one index page and one main chunk. And it would affect any other non-JS file types Vite allows in build.rollupOptions.input, such as css files bundled as entry points.
The problem seems to be that sentryVitePlugin borrows @sentry/rollup-plugin without accounting for the way Vite uses Rollup's "facade modules" for html and other non-JS file types. Technically, the issue is in @sentry/rollup-plugin: it probably shouldn't assume it's safe to inject JS into any arbitrary chunk. But while non-JS chunks are unusual in typical Rollup usage, they are a common pattern with Vite.
Here is an (AI-assisted) workaround that wraps sentryVitePlugin to block its transform and renderChunk hooks on html files. It might help suggest a fix. (I'm not a Vite or Rollup expert. It might make more sense to fix it in the Rollup bundler plugin. And there might be a better way to distinguish chunks that should be instrumented from those that should be left untouched.)
Thanks for reporting this and for the reproduction, I will take a look and I think it should be straightforward if we add empty chunk and html facade module detection skip.
Activity
linear commentedon Jan 3, 2026
BUNDLER-92
medmunds commentedon Jan 4, 2026
This probably also affects Vite single page apps; the extra chunk the plugin creates is just less obvious for a SPA with one index page and one main chunk. And it would affect any other non-JS file types Vite allows in build.rollupOptions.input, such as css files bundled as entry points.
The problem seems to be that sentryVitePlugin borrows @sentry/rollup-plugin without accounting for the way Vite uses Rollup's "facade modules" for html and other non-JS file types. Technically, the issue is in @sentry/rollup-plugin: it probably shouldn't assume it's safe to inject JS into any arbitrary chunk. But while non-JS chunks are unusual in typical Rollup usage, they are a common pattern with Vite.
Here is an (AI-assisted) workaround that wraps sentryVitePlugin to block its transform and renderChunk hooks on html files. It might help suggest a fix. (I'm not a Vite or Rollup expert. It might make more sense to fix it in the Rollup bundler plugin. And there might be a better way to distinguish chunks that should be instrumented from those that should be left untouched.)
logaretm commentedon Jan 5, 2026
Thanks for reporting this and for the reproduction, I will take a look and I think it should be straightforward if we add empty chunk and html facade module detection skip.