From 6bb5ce4db1a4e295a8ab1dc293c72355fb1a0073 Mon Sep 17 00:00:00 2001 From: ajnart Date: Tue, 1 Sep 2026 02:27:17 +0200 Subject: [PATCH] fix: support webpack development instrumentation --- apps/nextjs/next.config.ts | 25 +++++++++++++++++++------ apps/nextjs/src/instrumentation-noop.ts | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/apps/nextjs/next.config.ts b/apps/nextjs/next.config.ts index a2bef01b3..5d3c9fb5f 100644 --- a/apps/nextjs/next.config.ts +++ b/apps/nextjs/next.config.ts @@ -15,15 +15,14 @@ const withNextIntl = createNextIntlPlugin({ requestConfig: "../../packages/translation/src/request.ts", }); -const getDevelopmentServiceAliases = () => { +const developmentServicePackages = ["@homarr/tasks", "@homarr/websocket"] as const; + +const getDevelopmentServiceAliases = (target: string) => { if (process.env.NODE_ENV !== "development") { return undefined; } - return { - "@homarr/tasks": "./src/instrumentation-noop.ts", - "@homarr/websocket": "./src/instrumentation-noop.ts", - }; + return Object.fromEntries(developmentServicePackages.map((packageName) => [packageName, target])); }; const getDistDir = () => { @@ -65,7 +64,21 @@ const nextConfig: NextConfig = { root: path.resolve(import.meta.dirname, "../.."), // Development runs tasks and WebSocket as separate processes. These aliases // keep their production-only instrumentation imports out of the dev graph. - resolveAlias: getDevelopmentServiceAliases(), + resolveAlias: getDevelopmentServiceAliases("./src/instrumentation-noop.ts"), + }, + webpack(config, { dev, isServer }) { + if (!dev || !isServer) return config; + + const instrumentationNoopPath = path.resolve(import.meta.dirname, "src/instrumentation-noop.ts"); + const aliases = getDevelopmentServiceAliases(instrumentationNoopPath); + if (!aliases) return config; + + config.resolve.alias = { + ...config.resolve.alias, + ...aliases, + "./instrumentation-node": instrumentationNoopPath, + }; + return config; }, transpilePackages: ["@homarr/ui", "@homarr/notifications", "@homarr/modals", "@homarr/spotlight", "@homarr/widgets"], images: { diff --git a/apps/nextjs/src/instrumentation-noop.ts b/apps/nextjs/src/instrumentation-noop.ts index fee327293..b0f98545b 100644 --- a/apps/nextjs/src/instrumentation-noop.ts +++ b/apps/nextjs/src/instrumentation-noop.ts @@ -2,3 +2,4 @@ // next.config.ts keep production-only instrumentation imports out of the graph. export const instrumentationNoop = true; export const startupPromise = Promise.resolve(); +export const registerNodeInstrumentation = () => Promise.resolve();