Skip to content

Commit 7521536

Browse files
clydinvikerman
authored andcommitted
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 64463e7 commit 7521536

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
@@ -400,6 +400,14 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
400400
test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/,
401401
parser: { system: true },
402402
},
403+
{
404+
test: /[\/\\]hot[\/\\]emitter.js$/,
405+
parser: { node: { events: true } },
406+
},
407+
{
408+
test: /[\/\\]webpack-dev-server[\/\\]client[\/\\]utils[\/\\]createSocketUrl.js$/,
409+
parser: { node: { querystring: true } },
410+
},
403411
{
404412
test: /\.js$/,
405413
...buildOptimizerUseRule,

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

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

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

0 commit comments

Comments
 (0)