From 651098367ddf5461be7cda8a9d424f7798429b0e Mon Sep 17 00:00:00 2001 From: Abdelrahman Awad Date: Tue, 11 Aug 2026 00:45:05 -0400 Subject: [PATCH] fix(sveltekit): Move `sentrySvelteKit` off the runtime entry to `@sentry/sveltekit/vite` The server entry statically re-exported the Vite build plugin, pulling the build-time module graph (`@sentry/vite-plugin`, and through it `@babel/core`) into the runtime graph on any server-side import. Serverless bundlers that trace by reachability (`@vercel/nft`) then copied all of it into the function. Expose the plugin via a dedicated `@sentry/sveltekit/vite` subpath instead, so it is never reachable from the server entry. --- MIGRATION.md | 18 +++++++++++++++++- .../sveltekit-2-kit-tracing/vite.config.ts | 2 +- .../sveltekit-2-orchestrion/vite.config.ts | 2 +- .../sveltekit-2-svelte-5/vite.config.ts | 2 +- .../sveltekit-2.5.0-twp/vite.config.ts | 2 +- .../sveltekit-2/vite.config.js | 2 +- .../sveltekit-3/vite.config.js | 2 +- .../sveltekit-cloudflare-pages/vite.config.js | 2 +- packages/sveltekit/package.json | 5 +++++ packages/sveltekit/rollup.npm.config.mjs | 1 + packages/sveltekit/src/index.server.ts | 1 - packages/sveltekit/src/index.types.ts | 1 - 12 files changed, 30 insertions(+), 10 deletions(-) diff --git a/MIGRATION.md b/MIGRATION.md index b173b0714d68..b842d864a241 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -967,7 +967,23 @@ Sentry.init({ The same applies when looking the integration up by name, e.g. via `client.getIntegrationByName('OtlpIntegration')`. -## 6. Type Changes +### `sentrySvelteKit` moved to the `@sentry/sveltekit/vite` subpath export + +Affected SDKs: `@sentry/sveltekit`. + +The `sentrySvelteKit` Vite plugin is no longer re-exported from the main `@sentry/sveltekit` entry. Import it from `@sentry/sveltekit/vite` in your `vite.config.ts` instead: + +```ts +// vite.config.ts + +// before +import { sentrySvelteKit } from '@sentry/sveltekit'; + +// after +import { sentrySvelteKit } from '@sentry/sveltekit/vite'; +``` + +The main entry re-exported the build plugin statically, which pulled the whole build-time module graph (`@sentry/vite-plugin`, and through it `@babel/core`) into the server runtime graph whenever the SDK was imported in server code. Serverless bundlers that trace by reachability (e.g. `@vercel/nft`) then copied all of it into the function. Moving the plugin behind its own subpath keeps it off the runtime entry so it is never reachable from server code. - Several public types that used `any` now use `unknown` — including `StackFrame`, `SamplingContext`, `SentryError`, and `User`. You may need to narrow types explicitly where you previously relied on diff --git a/dev-packages/e2e-tests/test-applications/sveltekit-2-kit-tracing/vite.config.ts b/dev-packages/e2e-tests/test-applications/sveltekit-2-kit-tracing/vite.config.ts index 1a410bee7e11..be8b485d022a 100644 --- a/dev-packages/e2e-tests/test-applications/sveltekit-2-kit-tracing/vite.config.ts +++ b/dev-packages/e2e-tests/test-applications/sveltekit-2-kit-tracing/vite.config.ts @@ -1,4 +1,4 @@ -import { sentrySvelteKit } from '@sentry/sveltekit'; +import { sentrySvelteKit } from '@sentry/sveltekit/vite'; import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; diff --git a/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/vite.config.ts b/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/vite.config.ts index d902d792b3ae..a69799ae1373 100644 --- a/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/vite.config.ts +++ b/dev-packages/e2e-tests/test-applications/sveltekit-2-orchestrion/vite.config.ts @@ -1,4 +1,4 @@ -import { sentrySvelteKit } from '@sentry/sveltekit'; +import { sentrySvelteKit } from '@sentry/sveltekit/vite'; import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; diff --git a/dev-packages/e2e-tests/test-applications/sveltekit-2-svelte-5/vite.config.ts b/dev-packages/e2e-tests/test-applications/sveltekit-2-svelte-5/vite.config.ts index 1a410bee7e11..be8b485d022a 100644 --- a/dev-packages/e2e-tests/test-applications/sveltekit-2-svelte-5/vite.config.ts +++ b/dev-packages/e2e-tests/test-applications/sveltekit-2-svelte-5/vite.config.ts @@ -1,4 +1,4 @@ -import { sentrySvelteKit } from '@sentry/sveltekit'; +import { sentrySvelteKit } from '@sentry/sveltekit/vite'; import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; diff --git a/dev-packages/e2e-tests/test-applications/sveltekit-2.5.0-twp/vite.config.ts b/dev-packages/e2e-tests/test-applications/sveltekit-2.5.0-twp/vite.config.ts index 1a410bee7e11..be8b485d022a 100644 --- a/dev-packages/e2e-tests/test-applications/sveltekit-2.5.0-twp/vite.config.ts +++ b/dev-packages/e2e-tests/test-applications/sveltekit-2.5.0-twp/vite.config.ts @@ -1,4 +1,4 @@ -import { sentrySvelteKit } from '@sentry/sveltekit'; +import { sentrySvelteKit } from '@sentry/sveltekit/vite'; import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; diff --git a/dev-packages/e2e-tests/test-applications/sveltekit-2/vite.config.js b/dev-packages/e2e-tests/test-applications/sveltekit-2/vite.config.js index 1a410bee7e11..be8b485d022a 100644 --- a/dev-packages/e2e-tests/test-applications/sveltekit-2/vite.config.js +++ b/dev-packages/e2e-tests/test-applications/sveltekit-2/vite.config.js @@ -1,4 +1,4 @@ -import { sentrySvelteKit } from '@sentry/sveltekit'; +import { sentrySvelteKit } from '@sentry/sveltekit/vite'; import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; diff --git a/dev-packages/e2e-tests/test-applications/sveltekit-3/vite.config.js b/dev-packages/e2e-tests/test-applications/sveltekit-3/vite.config.js index 0488d11680ec..3e789da133e5 100644 --- a/dev-packages/e2e-tests/test-applications/sveltekit-3/vite.config.js +++ b/dev-packages/e2e-tests/test-applications/sveltekit-3/vite.config.js @@ -1,5 +1,5 @@ import adapter from '@sveltejs/adapter-node'; -import { sentrySvelteKit } from '@sentry/sveltekit'; +import { sentrySvelteKit } from '@sentry/sveltekit/vite'; import { sveltekit } from '@sveltejs/kit/vite'; import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; import { defineConfig } from 'vite'; diff --git a/dev-packages/e2e-tests/test-applications/sveltekit-cloudflare-pages/vite.config.js b/dev-packages/e2e-tests/test-applications/sveltekit-cloudflare-pages/vite.config.js index 13cf806e6a07..3c5293b7df20 100644 --- a/dev-packages/e2e-tests/test-applications/sveltekit-cloudflare-pages/vite.config.js +++ b/dev-packages/e2e-tests/test-applications/sveltekit-cloudflare-pages/vite.config.js @@ -1,4 +1,4 @@ -import { sentrySvelteKit } from '@sentry/sveltekit'; +import { sentrySvelteKit } from '@sentry/sveltekit/vite'; import { sveltekit } from '@sveltejs/kit/vite'; import { defineConfig } from 'vite'; diff --git a/packages/sveltekit/package.json b/packages/sveltekit/package.json index 487d8acf8af3..df16b362c1d4 100644 --- a/packages/sveltekit/package.json +++ b/packages/sveltekit/package.json @@ -41,6 +41,11 @@ "import": "./build/esm/index.server.js", "require": "./build/cjs/index.server.js" } + }, + "./vite": { + "types": "./build/types/vite/index.d.ts", + "import": "./build/esm/vite/index.js", + "require": "./build/cjs/vite/index.js" } }, "publishConfig": { diff --git a/packages/sveltekit/rollup.npm.config.mjs b/packages/sveltekit/rollup.npm.config.mjs index dc6003ab7698..e4d71a469e1e 100644 --- a/packages/sveltekit/rollup.npm.config.mjs +++ b/packages/sveltekit/rollup.npm.config.mjs @@ -13,6 +13,7 @@ export default makeNPMConfigVariants( 'src/client/svelte5BrowserTracing.ts', 'src/server/index.ts', 'src/worker/index.ts', + 'src/vite/index.ts', ], packageSpecificConfig: { // Keep the variant subpath external so the transpiled output preserves the import for the diff --git a/packages/sveltekit/src/index.server.ts b/packages/sveltekit/src/index.server.ts index d675a1c72820..0ce5251aa327 100644 --- a/packages/sveltekit/src/index.server.ts +++ b/packages/sveltekit/src/index.server.ts @@ -1,2 +1 @@ export * from './server'; -export * from './vite'; diff --git a/packages/sveltekit/src/index.types.ts b/packages/sveltekit/src/index.types.ts index 5404d001b205..135e466438d8 100644 --- a/packages/sveltekit/src/index.types.ts +++ b/packages/sveltekit/src/index.types.ts @@ -11,7 +11,6 @@ import type * as clientSdk from './client'; import type * as serverSdk from './server'; export * from './client'; -export * from './vite'; export * from './server'; export * from './worker';