Skip to content

Commit 6320e6c

Browse files
committed
fix(@angular-devkit/build-angular): support pnpm with ng serve
Webpack and its development server assume the presence of two node builtins (`events` & `querystring`). Do to package hoisting npm/yarn will usually place the shims for those two builtins at locations that webpack find them. This is however not guaranteed nor will it work with pnpm which strictly follows the prescribed dependency tree. To remedy this, the specific node shims are enabled only for the specific internal webpack files that are used within the development server. This ensures that the requirements of these files does not pollute the entire application. Fixes #13680
1 parent 77f2af0 commit 6320e6c

File tree

2 files changed

+22
-0
lines changed
  • packages/angular_devkit/build_angular/src

2 files changed

+22
-0
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts

+8
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,14 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
402402
test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/,
403403
parser: { system: true },
404404
},
405+
{
406+
test: /[\/\\]hot[\/\\]emitter.js$/,
407+
parser: { node: { events: true } },
408+
},
409+
{
410+
test: /[\/\\]webpack-dev-server[\/\\]client[\/\\]utils[\/\\]createSocketUrl.js$/,
411+
parser: { node: { querystring: true } },
412+
},
405413
{
406414
test: /\.js$/,
407415
...buildOptimizerUseRule,

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

+14
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,20 @@ function _addLiveReload(
407407
webpackConfig.plugins = [];
408408
}
409409

410+
// Enable the internal node plugins but no individual shims
411+
// This is need to allow module specific rules to include node shims
412+
// Only needed in dev server mode to support live reload capabilities in all package managers
413+
if (webpackConfig.node === false) {
414+
webpackConfig.node = {
415+
global: false,
416+
process: false,
417+
__filename: false,
418+
__dirname: false,
419+
Buffer: false,
420+
setImmediate: false,
421+
};
422+
}
423+
410424
// This allows for live reload of page when changes are made to repo.
411425
// https://webpack.js.org/configuration/dev-server/#devserver-inline
412426
let webpackDevServerPath;

0 commit comments

Comments
 (0)