Skip to content

Commit 17cae38

Browse files
committed
fix(@angular-devkit/build-angular): shim node events builtin for dev server
The dev server requires a node 'events' builtin shim to function. The dev server as written only currently works with package managers that hoist the `events` shim package to an accessible location. Hoisting is unfortunately not standardized and the assumption within the dev server will not hold true for all package managers. Closes angular#13680
1 parent 81acdd7 commit 17cae38

File tree

1 file changed

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

1 file changed

+13
-0
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,19 @@ export class DevServerBuilder implements Builder<DevServerBuilderOptions> {
290290
}
291291
if (!webpackConfig.entry.main) { webpackConfig.entry.main = []; }
292292
webpackConfig.entry.main.unshift(...entryPoints);
293+
294+
// The dev server live reload requires a node 'events' builtin shim to function.
295+
// The dev server as written only currently works with package managers
296+
// that hoist the `events` shim package to an accessible location.
297+
// Hoisting is unfortantely not standardized and the assumption within
298+
// the dev server will not hold true for all package managers.
299+
// The actual code is only accessed when hmr is enabled which allows
300+
// the 'events' import to be ignored in the non-hmr case.
301+
if (!webpackConfig.node) {
302+
webpackConfig.node = { events: options.hmr };
303+
} else if (typeof webpackConfig.node === 'object') {
304+
webpackConfig.node.events = webpackConfig.node.events || options.hmr;
305+
}
293306
}
294307

295308
private _addSslConfig(

0 commit comments

Comments
 (0)