kit: It looks like the new version of SvelteKit is incompatible with the @sentry/sveltekit package

Describe the bug

build failure

Reproduction

  1. clone the project: https://github.com/sopaco/saga-reader.git.
  2. execute bun run dev.

Logs

build

 [18 lines elided]
│       at emitError (node:events:1:13)
│ ✗ Build failed in 6.72s
│ error during build:
│ [vite-plugin-sveltekit-compile] Failed with code 1
│     at <anonymous> (/Users/jiangmeng/workspace/research/saga-reader/node_modules/@sveltejs/kit/src/utils/fork.js:65:17)
│     at emit (node:events:93:22)
│     at #onClose (node:worker_threads:216:44)
│ error: script "build" exited with code 1
│ beforeBuildCommand `bun run build` failed with exit code 1
│        Error beforeBuildCommand `bun run build` failed with exit code 1

dev

│ [219 lines elided]
│ 5021 |  */
│ 5022 | function originalPositionFor$1(map, needle) {
│ 5023 |     let { line, column, bias } = needle;
│ 5024 |     line--;
│ 5025 |     if (line < 0)
│ 5026 |         throw new Error(LINE_GTR_ZERO);
│                          ^
│ error: `line` must be greater than 0 (lines start at line 1)
│       at originalPositionFor$1 (/Users/Workspace/research/saga-reader/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:5026:19)

System Info

npx envinfo --system --npmPackages svelte,rollup,webpack --binaries --browsers

  System:
    OS: macOS 14.5
    CPU: (12) arm64 Apple M2 Pro
    Memory: 790.73 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
    bun: 1.2.15 - ~/.bun/bin/bun
  Browsers:
    Edge: 134.0.3124.51
    Safari: 17.5

Severity

annoyance

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 2
  • Comments: 16 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Released with version 9.28.1! Thanks so much for your help @eltigerchino!

I’ve found the issue and it’s because Vite is resolving to the CJS version of @sentry/sveltekit instead of an ESM version when bundling, causing the bundle to incorrectly import things (a default import instead of named imports).

Created a PR here https://github.com/getsentry/sentry-javascript/pull/16528

The workaround for now is to stay on SvelteKit 2.21.2 or add the following to your Vite config:

  ssr: {
    external: ['@sentry/sveltekit'],
  }

The latest Kit is bundling all deps that rely on SvelteKit so that class instantiations and instanceof checks work. Adding the package to vite.ssr.external ensures that it isn’t bundled (and therefore the current error wouldn’t appear).

I made a small repo here: https://stackblitz.com/edit/sveltejs-kit-template-default-kxvebrub

It has latest sveltekit + svelte installed and Sentry. If you run npm build, you will get errors.

Reverting the Sveltekit package back to 2.21.2 makes that error go away.

It looks like the new version of svelte is not compatible with the @sentry/sveltekit package. Removing the latter allows it to compile successfully.

Ok i can reproduce locally with bun and latest kit, this is a kit bug…let me see if i can move it there

Seems like issue in sentry with svelte. Currently using @sentry/sveltekit: ^8.48.0 with svelte: ^5.18.0.

Image