-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Description
When using @sentry/sveltekit with Vite 7.x and running svelte-check (or any operation that triggers Vite config resolution), the build fails with:
TypeError: sentryPlugins.find is not a function
at makeCustomSentryVitePlugins (sourceMaps.js:74:55)
at async sentrySvelteKit (sentryVitePlugins.js:64:31)
at async Promise.all (index 0)
at async asyncFlatten (config.js:2574:10)
at async resolveConfig (config.js:35429:68)
Root Cause Analysis
After investigating the source code of @sentry/sveltekit, @sentry/vite-plugin, unplugin, and Vite, I found the issue:
1. unplugin returns inconsistent types
In [email protected] (which @sentry/vite-plugin depends on), the Vite adapter returns either a single plugin OR an array:
// unplugin/src/vite/index.ts
return plugins.length === 1 ? plugins[0] : plugins; // Single object OR array!2. @sentry/sveltekit assumes an array
In @sentry/sveltekit/src/vite/sourceMaps.ts (line 85-87):
const sentryPlugins: Plugin[] = await sentryVitePlugin(mergedOptions);
const sentryViteDebugIdUploadPlugin = sentryPlugins.find( // FAILS if single object!
plugin => plugin.name === 'sentry-vite-debug-id-upload-plugin',
);3. During svelte-check, only one plugin is created
When svelte-check triggers config resolution, something causes sentryVitePlugin() to return only one plugin (likely the noop plugin when auth tokens aren't available), which unplugin converts to a single object instead of an array.
Steps to Reproduce
- Create a SvelteKit project with Vite 7.x
- Install
@sentry/sveltekit - Add
sentrySvelteKit()to vite.config.ts plugins - Run
svelte-checkorsvelte-kit sync && svelte-check
Environment
@sentry/sveltekit: 10.32.1vite: 7.3.0@sveltejs/kit: 2.49.xunplugin(transitive via @sentry/vite-plugin): 1.0.1
Workaround
Adding @sentry/sveltekit to ssr.external prevents Vite from bundling it during SSR/type-checking:
// vite.config.ts
export default defineConfig({
plugins: [
sentrySvelteKit({ /* ... */ }),
sveltekit(),
],
ssr: {
external: ["@sentry/sveltekit"], // Workaround for Vite 7 compatibility
},
});Suggested Fix
Either:
-
Defensive check in sourceMaps.ts: Wrap the result in an array if it's not already:
const sentryPlugins: Plugin[] = [await sentryVitePlugin(mergedOptions)].flat();
-
Update unplugin dependency: The current
@sentry/vite-pluginpins[email protected](current is 2.3.11). Newer versions may handle this differently. -
Document the workaround: Add
ssr.externalto the SvelteKit setup docs for Vite 7 users.
Related Issues
- It looks like the new version of SvelteKit is incompatible with the @sentry/sveltekit package sveltejs/kit#13869 (different issue but same workaround)
- vite-plugin > Type "" is not assignable to type PluginOption sentry-javascript-bundler-plugins#804 (Vite 7 type compatibility, closed)
Metadata
Metadata
Assignees
Projects
Status