Skip to content

Commit 5d21812

Browse files
committed
fix(@angular/build): disable strictPort when port 0 is used in dev-server
When port 0 is specified, an ephemeral port is selected. Previously, strictPort was hardcoded to true, which caused Vite to fail immediately if the ephemeral port was occupied during rebuilds or rapid restarts. strictPort is now set to false when port 0 is requested, allowing Vite to fall back to an available port.
1 parent 0ba4d8e commit 5d21812

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

packages/angular/build/src/builders/dev-server/options.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import { normalizeCacheOptions } from '../../utils/normalize-cache';
1313
import { ApplicationBuilderOptions } from '../application';
1414
import { Schema as DevServerOptions } from './schema';
1515

16-
export type NormalizedDevServerOptions = Awaited<ReturnType<typeof normalizeOptions>>;
16+
export type NormalizedDevServerOptions = Omit<
17+
Awaited<ReturnType<typeof normalizeOptions>>,
18+
'strictPort'
19+
> & {
20+
strictPort?: boolean;
21+
};
1722

1823
/**
1924
* Normalize the user provided options by creating full paths for all path based options
@@ -122,6 +127,7 @@ export async function normalizeOptions(
122127
buildTarget,
123128
host: host ?? 'localhost',
124129
port,
130+
strictPort: port !== 0,
125131
poll,
126132
open,
127133
verbose,

packages/angular/build/src/builders/dev-server/vite/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async function createServerConfig(
5656
ssrFiles,
5757
},
5858
port: serverOptions.port,
59-
strictPort: true,
59+
strictPort: serverOptions.strictPort ?? true,
6060
host: serverOptions.host,
6161
open: serverOptions.open,
6262
allowedHosts: serverOptions.allowedHosts,

0 commit comments

Comments
 (0)