diff --git a/packages/@angular/cli/upgrade/version.ts b/packages/@angular/cli/upgrade/version.ts index a33e606c760f..5b5d5dcaf7c7 100644 --- a/packages/@angular/cli/upgrade/version.ts +++ b/packages/@angular/cli/upgrade/version.ts @@ -94,7 +94,9 @@ export class Version { if (v.isLocal()) { console.warn(yellow('Using a local version of angular. Proceeding with care...')); } else { - if (!v.isGreaterThanOrEqualTo(new SemVer('2.3.1'))) { + // Check if major is not 0, so that we stay compatible with local compiled versions + // of angular. + if (!v.isGreaterThanOrEqualTo(new SemVer('2.3.1')) && v.major != 0) { console.error(bold(red(stripIndents` This version of CLI is only compatible with angular version 2.3.1 or better. Please upgrade your angular version, e.g. by running: diff --git a/packages/@ngtools/webpack/src/plugin.ts b/packages/@ngtools/webpack/src/plugin.ts index f526e52da45e..bff8a01e15ef 100644 --- a/packages/@ngtools/webpack/src/plugin.ts +++ b/packages/@ngtools/webpack/src/plugin.ts @@ -269,13 +269,26 @@ export class AotPlugin implements Tapable { // Add lazy modules to the context module for @angular/core/src/linker compiler.plugin('context-module-factory', (cmf: any) => { + const angularCorePackagePath = require.resolve('@angular/core/package.json'); + const angularCorePackageJson = require(angularCorePackagePath); + const angularCoreModulePath = path.resolve(path.dirname(angularCorePackagePath), + angularCorePackageJson['module']); + // Pick the last part after the last node_modules instance. We do this to let people have + // a linked @angular/core or cli which would not be under the same path as the project + // being built. + const angularCoreModuleDir = path.dirname(angularCoreModulePath).split(/node_modules/).pop(); + cmf.plugin('after-resolve', (result: any, callback: (err?: any, request?: any) => void) => { if (!result) { return callback(); } - // alter only request from @angular/core/src/linker - if (!result.resource.endsWith(path.join('@angular/core/src/linker'))) { + // Alter only request from Angular; + // @angular/core/src/linker matches for 2.*.*, + // The other logic is for flat modules and requires reading the package.json of angular + // (see above). + if (!result.resource.endsWith(path.join('@angular/core/src/linker')) + && (angularCoreModuleDir && !result.resource.endsWith(angularCoreModuleDir))) { return callback(null, result); }