Skip to content

[sentry/cloudflare] Sentry import breaks Env type #16099

Open
@shmuli9

Description

@shmuli9

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/cloudflare

SDK Version

9.13.0

Framework Version

React Router 7.5.1, Vite 6.3.0, Wrangler 4.12.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

// worker file: ./workers/app.ts

import { getLoadContext } from "load-context";
import { createRequestHandler } from "react-router";
import * as Sentry from "@sentry/cloudflare"; // <-- this line breaks the Env types

const requestHandler = createRequestHandler(
  () => import("virtual:react-router/server-build"),
  import.meta.env.MODE
);

export default {
  async fetch(request, env, ctx) {
    const url = new URL(request.url);
    if (url.pathname.startsWith("/r2")) {
      const key = url.pathname.replace(/^\/r2\//, "");
      const object = await env.BUCKET.get(key);
      if (!object) {
        return new Response("Not found", { status: 404 });
      }
      return new Response(object.body, {
        headers: { "Content-Type": "image/jpeg" },
      });
    }

    const loadContext = getLoadContext({
      request,
      context: { cloudflare: { env, ctx } },
    });
    return requestHandler(request, loadContext);
  },
} satisfies ExportedHandler<Env>;

Steps to Reproduce

  1. installed @sentry/cloudflare v9.13.0
  2. added the import to workers/app.ts
    import * as Sentry from "@sentry/cloudflare"; // <-- this line breaks the Env types
  3. my env types break in when i typecheck
  4. commenting out the import fixes the type errors
    // import * as Sentry from "@sentry/cloudflare";

Expected Result

Types should not be corrupted by import Sentry

Actual Result

Broken:

Image

Image

Working (when import is commented out):

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions