Repository navigation
@sentry/nextjs 10.75.2 / 10.75.3 break Next.js on Cloudflare Workers (OpenNext): "An error occurred while loading the instrumentation hook" #25683
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
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
- Next.js 15.5 App Router app deployed to Cloudflare Workers with
@opennextjs/cloudflare, using the setup above, on@sentry/nextjs10.75.0. Everything works. - Upgrade
@sentry/nextjsto 10.75.2 (to pick up the fix for GHSA-mchm-gjx6-7h55).npx opennextjs-cloudflare buildsucceeds. - 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/catchinsidenode_modules:/,/search, a villa route, and/auth/signinreturned 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.
Metadata
Metadata
Assignees
Projects
- StatusShow more project fieldsNo status
Activity
linear-code commentedon Oct 23, 2026
JS-3994
logaretm commentedon Oct 24, 2026
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.
fix(v10/nextjs): Don't crash Cloudflare workers on import of the Next…