Skip to content

Commit d9d233e

Browse files
clydinmgechev
authored andcommitted
fix(@angular/cli): inform user and error if schematics package is in unreachable location (#16466)
This is a workaround for the schematics runtime to support the requirement of packages containing migrations (or other schematics) to not have a direct/runtime dependency on the schematics package. Closes: #16392
1 parent 5458477 commit d9d233e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

packages/angular/cli/commands/update-impl.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,28 @@ export class UpdateCommand extends Command<UpdateCommandSchema> {
241241

242242
// tslint:disable-next-line:no-big-function
243243
async run(options: UpdateCommandSchema & Arguments) {
244+
// Check if the @angular-devkit/schematics package can be resolved from the workspace root
245+
// This works around issues with packages containing migrations that cannot directly depend on the package
246+
// This check can be removed once the schematic runtime handles this situation
247+
try {
248+
require.resolve('@angular-devkit/schematics', { paths: [this.workspace.root] });
249+
} catch (e) {
250+
if (e.code === 'MODULE_NOT_FOUND') {
251+
this.logger.fatal(
252+
'The "@angular-devkit/schematics" package cannot be resolved from the workspace root directory. ' +
253+
'This may be due to an unsupported node modules structure.\n' +
254+
'Please remove both the "node_modules" directory and the package lock file; and then reinstall.\n' +
255+
'If this does not correct the problem, ' +
256+
'please temporarily install the "@angular-devkit/schematics" package within the workspace. ' +
257+
'It can be removed once the update is complete.',
258+
);
259+
260+
return 1;
261+
}
262+
263+
throw e;
264+
}
265+
244266
// Check if the current installed CLI version is older than the latest version.
245267
if (await this.checkCLILatestVersion(options.verbose, options.next)) {
246268
this.logger.warn(

0 commit comments

Comments
 (0)