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:
+12
-5
@@ -1,6 +1,5 @@
|
||||
import path from "path";
|
||||
import type { NextConfig } from "next";
|
||||
import { withSentryConfig } from "@sentry/nextjs";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
output: "standalone",
|
||||
@@ -48,10 +47,18 @@ const nextConfig: NextConfig = {
|
||||
|
||||
// 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
|
||||
export default process.env.NODE_ENV === "production"
|
||||
? withSentryConfig(nextConfig, {
|
||||
// Sentry only in production — dynamic import avoids side effects in dev
|
||||
let exportedConfig: NextConfig = nextConfig;
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
try {
|
||||
const { withSentryConfig } = require("@sentry/nextjs");
|
||||
exportedConfig = withSentryConfig(nextConfig, {
|
||||
silent: true,
|
||||
sourcemaps: { disable: true },
|
||||
telemetry: false,
|
||||
})
|
||||
: nextConfig;
|
||||
});
|
||||
} catch {
|
||||
// Sentry not available — use raw config
|
||||
}
|
||||
}
|
||||
export default exportedConfig;
|
||||
|
||||
Reference in New Issue
Block a user