Skip to content

@sentry/nextjs 10.75.2 / 10.75.3 break Next.js on Cloudflare Workers (OpenNext): "An error occurred while loading the instrumentation hook" #25683

Closed

Description

@miya-start

Is there an existing issue for this?

This report concerns the tested v10 versions below. We have not tried v11.

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

10.75.2 (also 10.75.3). Works on 10.75.0.

Framework Version

Next.js 15.5.28 (App Router), @opennextjs/cloudflare 1.20.12, wrangler 4.151.1. Cloudflare Workers with compatibility_flags = ["nodejs_compat"], compatibility_date = "2025-09-10".

Link to Sentry event

No response

Reproduction Example/SDK Setup

instrumentation.ts:

import * as Sentry from "@sentry/nextjs";

export async function register() {
  if (process.env.NEXT_RUNTIME === "nodejs") {
    await import("./sentry.server.config");
  }
  if (process.env.NEXT_RUNTIME === "edge") {
    await import("./sentry.edge.config");
  }
}

export const onRequestError = Sentry.captureRequestError;

next.config.js wraps the config with withSentryConfig (org, project, authToken, hideSourceMaps). No tunnelRoute is configured.

Steps to Reproduce

  1. Next.js 15.5 App Router app deployed to Cloudflare Workers with @opennextjs/cloudflare, using the setup above, on @sentry/nextjs 10.75.0. Everything works.
  2. Upgrade @sentry/nextjs to 10.75.2 (to pick up the fix for GHSA-mchm-gjx6-7h55). npx opennextjs-cloudflare build succeeds.
  3. Request any server-rendered page. We saw the failure on our staging deployment on Cloudflare Workers (10.75.2), and reproduced it locally with npx opennextjs-cloudflare preview (10.75.2 and 10.75.3).

Expected Result

Pages render as they do on 10.75.0.

Actual Result

Every server-rendered route returns 500 with {"message":"Server failed to respond.","details":{}}. Static assets are still served. The worker logs repeat:

Failed to prepare server Error: An error occurred while loading the instrumentation hook
NextJS request failed. Error: An error occurred while loading the instrumentation hook

No more detailed cause is logged.

Additional Context

This looks like it comes from #24475 (released in 10.75.1). It changed packages/nextjs/src/config/util.ts to call createRequire at module scope:

  • build/cjs/config/util.js: sdkRequire = module$1.createRequire(__filename);
  • build/esm/config/util.js: sdkRequire = createRequire(import.meta.url);

At runtime this module is reachable from the server entry: build/cjs/index.server.js → ./config/deprecatedWithSentryConfig.js → … → config/util.js (for example via config/withSentryConfig/getFinalConfigObject.js). Importing @sentry/nextjs from the instrumentation file therefore runs this call when the module loads. The isolated test below points to this module-scope initialization as the trigger in our Workers setup; we have not captured the underlying exception.

What we observed:

  • Staging deployment on Cloudflare Workers: 10.75.0 works; 10.75.2 returns 500 on all server-rendered pages with the error above.
  • Locally with opennextjs-cloudflare preview:
    • 10.75.0: tested server-rendered routes returned 200.
    • 10.75.2 and 10.75.3: tested server-rendered routes returned 500 with the error above.
    • 10.75.2 with only that one statement (cjs and esm) wrapped in try/catch inside node_modules: /, /search, a villa route, and /auth/signin returned 200 again, with no instrumentation-hook errors.

The same statement also appears in the published 10.75.1 and 10.76.2 packages (package inspection only; we did not run them). We have not tried 11.x.

A possible fix: create sdkRequire lazily inside the function that needs it (or guard the call), so that importing the server entry does not eagerly call createRequire. Another option is to keep build-time config utilities out of the runtime server entry.

Activity

  1. linear-code commented on Oct 23, 2026

    @linear-code
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Oct 23, 2026
  3. logaretm commented on Oct 24, 2026

    @logaretm
    Member

    Thanks for the report, it doesn't seem like v11 has the same issue since it doesn't pull in the config API. I have a PR up for it.

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Oct 24, 2026
  5. self-assigned this
    on Oct 24, 2026
  6. added a commit that references this issue on Oct 27, 2026
    0664050
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions