Skip to content

Commit 25d928b

Browse files
committed
fix(@angular-devkit/build-angular): fix hanging terminal when browser-sync is not installed
Running the SSR dev server when `browser-sync` is not installed would print the error, but then build the browser and server targets, then hang and never return control to the user until they manually Ctrl+C. This change skips building at all if `browser-sync` is not installed, immediately returning control to the user. This is a simple workaround, but there are two deeper bugs which would benefit from investigation: 1. Figure out why NPM sometimes doesn't install `browser-sync`. It was happening inconsistently for me when running `ng add @angular/ssr`. 2. Figure out why Architect does not cancel/await targets still executing when a builder completes. (cherry picked from commit 5d79ab7)
1 parent ea5ae68 commit 25d928b

File tree

1 file changed

+14
-13
lines changed
  • packages/angular_devkit/build_angular/src/builders/ssr-dev-server

1 file changed

+14
-13
lines changed

packages/angular_devkit/build_angular/src/builders/ssr-dev-server/index.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ export function execute(
6262
options: SSRDevServerBuilderOptions,
6363
context: BuilderContext,
6464
): Observable<SSRDevServerBuilderOutput> {
65+
let browserSync: typeof import('browser-sync');
66+
try {
67+
browserSync = require('browser-sync');
68+
} catch {
69+
return of({
70+
success: false,
71+
error:
72+
// eslint-disable-next-line max-len
73+
'Required dependency `browser-sync` is not installed, most likely you need to run `npm install browser-sync --save-dev` in your project.',
74+
});
75+
}
76+
77+
const bsInstance = browserSync.create();
78+
6579
const browserTarget = targetFromTargetString(options.browserTarget);
6680
const serverTarget = targetFromTargetString(options.serverTarget);
6781
const getBaseUrl = (bs: BrowserSyncInstance) =>
@@ -80,19 +94,6 @@ export function execute(
8094
verbose: options.verbose,
8195
} as json.JsonObject);
8296

83-
let browserSync: typeof import('browser-sync');
84-
try {
85-
browserSync = require('browser-sync');
86-
} catch {
87-
return of({
88-
success: false,
89-
error:
90-
'"browser-sync" is not installed, most likely you need to run `npm install browser-sync --save-dev` in your project.',
91-
});
92-
}
93-
94-
const bsInstance = browserSync.create();
95-
9697
context.logger.error(tags.stripIndents`
9798
****************************************************************************************
9899
This is a simple server for use in testing or debugging Angular applications locally.

0 commit comments

Comments
 (0)