Skip to content

Sentry doesn't work with Wrangler Pages + Sveltekit #18541

@ZombieChibiXD

Description

@ZombieChibiXD

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/sveltekit

SDK Version

^10.31.0

Framework Version

"@sentry/sveltekit": "^10.31.0",

Link to Sentry event

No response

Reproduction Example/SDK Setup

//Hooks.server.ts
import { sequence } from '@sveltejs/kit/hooks';
import { handleErrorWithSentry, sentryHandle, initCloudflareSentryHandle } from '@sentry/sveltekit';
import * as Sentry from '@sentry/sveltekit';
import type { Handle } from '@sveltejs/kit';

export const handle = sequence(
	initCloudflareSentryHandle({
		dsn: 'https://bb5d40cdfe67937feac4980d449d83b5@o4510548762755072.ingest.us.sentry.io/4510548807122944',
		// Adds request headers and IP for users, for more info visit:
		// https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii
		sendDefaultPii: true
	}),
	sentryHandle(),
	({ event, resolve }) => {
		return resolve(event, {
			transformPageChunk: ({ html }) => html.replace('%lang%', event.locals.locale ?? 'en')
		});
	}
);

export const handleError = Sentry.handleErrorWithSentry();


//Hooks.client.ts
import { handleErrorWithSentry, replayIntegration } from "@sentry/sveltekit";
import * as Sentry from '@sentry/sveltekit';

Sentry.init({
  dsn: 'https://bb5d40cdfe67937feac4980d449d83b5@o4510548762755072.ingest.us.sentry.io/4510548807122944',

  tracesSampleRate: 1.0,

  // Enable logs to be sent to Sentry
  enableLogs: true,

  // This sets the sample rate to be 10%. You may want this to be 100% while
  // in development and sample at a lower rate in production
  replaysSessionSampleRate: 0.1,

  // If the entire session is not sampled, use the below sample rate to sample
  // sessions when an error occurs.
  replaysOnErrorSampleRate: 1.0,

  // If you don't want to use Session Replay, just remove the line below:
  integrations: [replayIntegration()],

  // Enable sending user PII (Personally Identifiable Information)
  // https://docs.sentry.io/platforms/javascript/guides/sveltekit/configuration/options/#sendDefaultPii
  sendDefaultPii: true,
});

// If you have a custom error handler, pass it to `handleErrorWithSentry`
export const handleError = handleErrorWithSentry();
// Instrumentation.server.ts
import * as Sentry from '@sentry/sveltekit';

Sentry.init({
  dsn: 'https://bb5d40cdfe67937feac4980d449d83b5@o4510548762755072.ingest.us.sentry.io/4510548807122944',

  tracesSampleRate: 1.0,

  // Enable logs to be sent to Sentry
  enableLogs: true,

  // uncomment the line below to enable Spotlight (https://spotlightjs.com)
  // spotlight: import.meta.env.DEV,
});

Steps to Reproduce

Attempt npm run build
Attempt npm wrangler pages dev
Failed because of

npx wrangler pages dev

 ⛅️ wrangler 4.50.0 (update available 4.55.0)
─────────────────────────────────────────────
X [ERROR] Build failed with 1 error:

  X [ERROR] Could not resolve
  "./..outputserverinstrumentation.server.js"

      _worker.js:1:7:
        1 │ import './..\output\server\instrumentation.server.js';
          ╵        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expected Result

It should deploy the website so I can deploy on cloudflare pages

Actual Result

npx wrangler pages dev

 ⛅️ wrangler 4.50.0 (update available 4.55.0)
─────────────────────────────────────────────
X [ERROR] Build failed with 1 error:

  X [ERROR] Could not resolve
  "./..outputserverinstrumentation.server.js"

      _worker.js:1:7:
        1 │ import './..\output\server\instrumentation.server.js';
          ╵        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Additional Context

No response

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Waiting for: Community

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions