Skip to content

Sentry sourcemap use @vitejs/plugin-legacy and @sentry/vite-plugin conflict. #564

@itaober

Description

@itaober

Environment

Node: v18.16.0
Vite: v5.3.1 (latest)
@sentry/vite-plugin: ^2.20.0
@vitejs/plugin-legacy: ^5.4.1
Project created using npm create vite, and choose React + TypeScript

What version are you running? Etc.

Steps to Reproduce

  1. Create a new Vite project.
  2. Config @vitejs/plugin-legacy.
  3. Config sentryVitePlugin, like this:
    vite.config.ts:
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import legacy from "@vitejs/plugin-legacy";
import { sentryVitePlugin } from "@sentry/vite-plugin";

// https://vitejs.dev/config/
export default defineConfig({
  build: {
    sourcemap: true,
  },
  plugins: [
    react(),
    legacy({
      targets: ["defaults", "not IE 11"],
    }),
    // notice: ... is my private config
    sentryVitePlugin({
      url: "...",
      org: "...",
      project: "...",
      authToken: "...",
      release: {
        name: "...",
      },
      sourcemaps: {
        assets: "dist/assets/**",
        ignore: ["node_modules"],
        filesToDeleteAfterUpload: "dist/**/*.map",
      },
    }),
  ],
});
  1. Add the following to App.tsx to test:
    App.tsx:
// ...
<button
  onClick={() => {
      throw new Error("VITE SENTRY");
    })
  }
>
  count is {count}
</button>
// ...

Expected Result

The expected result is similar to the second image under the "Actual Result" section.

Actual Result

With the legacy plugin enabled:
image

Without the legacy plugin:
vite.config.ts:

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import legacy from "@vitejs/plugin-legacy";
import { sentryVitePlugin } from "@sentry/vite-plugin";

// https://vitejs.dev/config/
export default defineConfig({
  build: {
    sourcemap: true,
  },
  plugins: [
    react(),
    // notice: ... is my private config
    sentryVitePlugin({
      url: "...",
      org: "...",
      project: "...",
      authToken: "...",
      release: {
        name: "...",
      },
      sourcemaps: {
        assets: "dist/assets/**",
        ignore: ["node_modules"],
        filesToDeleteAfterUpload: "dist/**/*.map",
      },
    }),
  ],
});

This configuration works correctly:
image

When using the legacy plugin, the build uploads two sourcemaps:
image
Without the legacy plugin, only one sourcemap is uploaded:
image

Issue

I need to use the legacy plugin, but it seems incompatible with Sentry sourcemaps. Any help would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions