diff --git a/instrumentation.ts b/instrumentation.ts index 931051572a..f2e0fa3aeb 100644 --- a/instrumentation.ts +++ b/instrumentation.ts @@ -94,6 +94,7 @@ export async function register(): Promise { return shutdownPromise; }; - process.once('SIGTERM', () => void shutdown()); - process.once('SIGINT', () => void shutdown()); + // Imported dynamically so the Edge bundle never contains `process.once`. + const { registerShutdownSignals } = await import('@/lib/server/shutdown-signals'); + registerShutdownSignals(shutdown); } diff --git a/lib/server/shutdown-signals.ts b/lib/server/shutdown-signals.ts new file mode 100644 index 0000000000..663548f707 --- /dev/null +++ b/lib/server/shutdown-signals.ts @@ -0,0 +1,11 @@ +/** + * Node-only shutdown signal wiring. + * + * Kept out of `instrumentation.ts` so the Edge runtime bundle never contains + * `process.once`, which Next's Edge compiler rejects as a Node.js API. The + * parent module imports this dynamically and only on the Node.js runtime. + */ +export function registerShutdownSignals(shutdown: () => Promise): void { + process.once('SIGTERM', () => void shutdown()); + process.once('SIGINT', () => void shutdown()); +}