Skip to content

Commit 8cec3cd

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 run `ng add @angular/ssr`. 2. Figure out why Architect does not cancel/await targets still executing when a builder completes.
1 parent 4fcce7d commit 8cec3cd

File tree

1 file changed

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

1 file changed

+13
-13
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ 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+
'Required dependency `browser-sync` is not installed, most likely you need to run `npm install browser-sync --save-dev` in your project.',
73+
});
74+
}
75+
76+
const bsInstance = browserSync.create();
77+
6578
const browserTarget = targetFromTargetString(options.browserTarget);
6679
const serverTarget = targetFromTargetString(options.serverTarget);
6780
const getBaseUrl = (bs: BrowserSyncInstance) =>
@@ -80,19 +93,6 @@ export function execute(
8093
verbose: options.verbose,
8194
} as json.JsonObject);
8295

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-
9696
context.logger.error(tags.stripIndents`
9797
****************************************************************************************
9898
This is a simple server for use in testing or debugging Angular applications locally.

0 commit comments

Comments
 (0)