Skip to content

Commit 30fb86c

Browse files
committed
fix(@angular/cli): resolve in all available node_modules
When @angular/cli dependencies (like @ngtool/webpack for example) are installed in its node_modules (as node_modules/@angular/cli/node_modules for example) webpack isn't seeing them. By using a subset of the current `module.paths`, containing all the node_modules from the current file to the root, we always webpack to discover those modules.
1 parent ec28715 commit 30fb86c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

packages/@angular/cli/custom-typings.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ interface IWebpackDevServerConfigurationOptions {
2424
public?: string;
2525
disableHostCheck?: boolean;
2626
}
27+
28+
29+
interface NodeModule {
30+
paths: string[];
31+
}

packages/@angular/cli/models/webpack-configs/common.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
2323
const { projectRoot, buildOptions, appConfig } = wco;
2424

2525
const appRoot = path.resolve(projectRoot, appConfig.root);
26-
const nodeModules = path.resolve(projectRoot, 'node_modules');
26+
const projectRootNodeModules = path.resolve(projectRoot, 'node_modules');
27+
const nodeModules = module.paths.slice(0, module.paths.indexOf(projectRootNodeModules) + 1);
2728

2829
let extraPlugins: any[] = [];
2930
let extraRules: any[] = [];
@@ -67,10 +68,10 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
6768
devtool: buildOptions.sourcemaps ? 'source-map' : false,
6869
resolve: {
6970
extensions: ['.ts', '.js'],
70-
modules: ['node_modules', nodeModules],
71+
modules: [appRoot].concat(nodeModules),
7172
},
7273
resolveLoader: {
73-
modules: [nodeModules]
74+
modules: nodeModules
7475
},
7576
context: projectRoot,
7677
entry: entryPoints,
@@ -82,7 +83,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
8283
},
8384
module: {
8485
rules: [
85-
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [nodeModules] },
86+
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: nodeModules },
8687
{ test: /\.json$/, loader: 'json-loader' },
8788
{ test: /\.html$/, loader: 'raw-loader' },
8889
{ test: /\.(eot|svg)$/, loader: `file-loader?name=[name]${hashFormat.file}.[ext]` },

0 commit comments

Comments
 (0)