fix: disable Sentry webpack wrapper in dev mode

The withSentryConfig() wrapper caused recurring worker.js crashes
in Next.js dev mode (vendor-chunks/lib/worker.js MODULE_NOT_FOUND).
This crashed the server mid-request during image generation and
other long-running operations.

Fix: only apply withSentryConfig in production. In dev mode, use
the raw Next.js config. Sentry instrumentation also gated to
production only.

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
2026-03-23 18:28:02 +01:00
parent e766309c6c
commit 05fd0e21ea
2 changed files with 24 additions and 15 deletions
+9 -7
View File
@@ -45,10 +45,12 @@ const nextConfig: NextConfig = {
}, },
}; };
export default withSentryConfig(nextConfig, { // Only wrap with Sentry in production — the worker.js crash in dev mode
silent: true, // (vendor-chunks/lib/worker.js MODULE_NOT_FOUND) makes the dev server unstable
sourcemaps: { export default process.env.NODE_ENV === "production"
disable: true, ? withSentryConfig(nextConfig, {
}, silent: true,
telemetry: false, sourcemaps: { disable: true },
}); telemetry: false,
})
: nextConfig;
+15 -8
View File
@@ -1,12 +1,19 @@
import * as Sentry from "@sentry/nextjs";
export async function register() { export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") { // Only load Sentry in production — the worker.js crash in dev mode
await import("../sentry.server.config"); // (vendor-chunks/lib/worker.js MODULE_NOT_FOUND) makes the dev server unstable
} if (process.env.NODE_ENV === "production") {
if (process.env.NEXT_RUNTIME === "edge") { if (process.env.NEXT_RUNTIME === "nodejs") {
await import("../sentry.edge.config"); await import("../sentry.server.config");
}
if (process.env.NEXT_RUNTIME === "edge") {
await import("../sentry.edge.config");
}
} }
} }
export const onRequestError = Sentry.captureRequestError; export async function onRequestError(...args: unknown[]) {
if (process.env.NODE_ENV === "production") {
const Sentry = await import("@sentry/nextjs");
(Sentry.captureRequestError as Function)(...args);
}
}