From f3a5970fca0a196b1ac905306257d65bab3b1325 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:16:37 -0400 Subject: [PATCH] fix(@angular/build): lazy load Node.js inspector for dev server The Node.js inspector will now only be imported if SSR is enabled and the `inspect` option is used. This prevents potential failures when a custom Node.js binary build is used that has not enabled inspector usage. While this is not common, loading the inspector on demand is a minimal change that also avoids loading code that will not be used for the majority of development server usage. (cherry picked from commit 34908a3fcba304da6916b2113863751500268a8c) --- packages/angular/build/src/builders/dev-server/vite-server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/angular/build/src/builders/dev-server/vite-server.ts b/packages/angular/build/src/builders/dev-server/vite-server.ts index 239abd4401c7..d55e9fb92f72 100644 --- a/packages/angular/build/src/builders/dev-server/vite-server.ts +++ b/packages/angular/build/src/builders/dev-server/vite-server.ts @@ -10,7 +10,6 @@ import type { BuilderContext } from '@angular-devkit/architect'; import type { Plugin } from 'esbuild'; import assert from 'node:assert'; import { readFile } from 'node:fs/promises'; -import inspector from 'node:inspector'; import { builtinModules } from 'node:module'; import { basename, join } from 'node:path'; import type { Connect, DepOptimizationConfig, InlineConfig, ViteDevServer } from 'vite'; @@ -265,6 +264,7 @@ export async function* serveWithVite( if (browserOptions.ssr && serverOptions.inspect) { const { host, port } = serverOptions.inspect as { host?: string; port?: number }; + const { default: inspector } = await import('node:inspector'); inspector.open(port, host, true); context.addTeardown(() => inspector.close()); }