Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): support pnpm with ng serve
Browse files Browse the repository at this point in the history
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
  • Loading branch information
clydin authored and vikerman committed Jul 26, 2019
1 parent 64463e7 commit 7521536
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Expand Up @@ -400,6 +400,14 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/,
parser: { system: true },
},
{
test: /[\/\\]hot[\/\\]emitter.js$/,
parser: { node: { events: true } },
},
{
test: /[\/\\]webpack-dev-server[\/\\]client[\/\\]utils[\/\\]createSocketUrl.js$/,
parser: { node: { querystring: true } },
},
{
test: /\.js$/,
...buildOptimizerUseRule,
Expand Down
14 changes: 14 additions & 0 deletions packages/angular_devkit/build_angular/src/dev-server/index.ts
Expand Up @@ -406,6 +406,20 @@ function _addLiveReload(
webpackConfig.plugins = [];
}

// Enable the internal node plugins but no individual shims
// This is needed to allow module specific rules to include node shims
// Only needed in dev server mode to support live reload capabilities in all package managers
if (webpackConfig.node === false) {
webpackConfig.node = {
global: false,
process: false,
__filename: false,
__dirname: false,
Buffer: false,
setImmediate: false,
};
}

// This allows for live reload of page when changes are made to repo.
// https://webpack.js.org/configuration/dev-server/#devserver-inline
let webpackDevServerPath;
Expand Down

0 comments on commit 7521536

Please sign in to comment.