fix: eliminate Sentry import side effects crashing dev server

The static import of @sentry/nextjs at module level triggered worker
thread creation even when withSentryConfig was only called in production.
This caused recurring "Cannot find module vendor-chunks/lib/worker.js"
crashes that killed the dev server mid-request.

Fix: replaced static import with dynamic require() inside a
NODE_ENV === "production" block. In dev mode, the Sentry module
is never loaded at all.

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
2026-03-26 12:00:57 +01:00
parent be2d2c0d56
commit 8be4ef47cd
+12 -5
View File
@@ -1,6 +1,5 @@
import path from "path"; import path from "path";
import type { NextConfig } from "next"; import type { NextConfig } from "next";
import { withSentryConfig } from "@sentry/nextjs";
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
output: "standalone", output: "standalone",
@@ -48,10 +47,18 @@ const nextConfig: NextConfig = {
// Only wrap with Sentry in production — the worker.js crash in dev mode // Only wrap with Sentry in production — the worker.js crash in dev mode
// (vendor-chunks/lib/worker.js MODULE_NOT_FOUND) makes the dev server unstable // (vendor-chunks/lib/worker.js MODULE_NOT_FOUND) makes the dev server unstable
export default process.env.NODE_ENV === "production" // Sentry only in production — dynamic import avoids side effects in dev
? withSentryConfig(nextConfig, { let exportedConfig: NextConfig = nextConfig;
if (process.env.NODE_ENV === "production") {
try {
const { withSentryConfig } = require("@sentry/nextjs");
exportedConfig = withSentryConfig(nextConfig, {
silent: true, silent: true,
sourcemaps: { disable: true }, sourcemaps: { disable: true },
telemetry: false, telemetry: false,
}) });
: nextConfig; } catch {
// Sentry not available — use raw config
}
}
export default exportedConfig;