angular-cli: ng update fails with "Cannot find module '@angular-devkit/schematics'"

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Description

Hi there, after reading a tweet from Igor to test out the new RC of ng9 I tried it on our application. The update command is not able to be finished even with flag --force due to the log below.

πŸ”₯ Exception or Error


ng update @angular/core @angular/cli --next --force
The installed Angular CLI version is older than the latest pre-release version.
Installing a temporary version to perform the update.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Using package manager: 'npm'
Collecting installed dependencies...
Found 74 dependencies.
Fetching dependency metadata from registry...
                  Package "@angular/core" has a missing peer dependency of "tslib" @ "^1.10.0".
                  Package "@angular/compiler-cli" has a missing peer dependency of "tslib" @ "^1.10.0".
                  Package "@angular/compiler" has a missing peer dependency of "tslib" @ "^1.10.0".
                  Package "@angular/common" has a missing peer dependency of "tslib" @ "^1.10.0".
                  Package "@angular/animations" has a missing peer dependency of "tslib" @ "^1.10.0".
                  Package "@angular/platform-browser" has a missing peer dependency of "tslib" @ "^1.10.0".
                  Package "@angular/forms" has a missing peer dependency of "tslib" @ "^1.10.0".
                  Package "@angular/router" has a missing peer dependency of "tslib" @ "^1.10.0".
                  Package "@angular/platform-browser-dynamic" has a missing peer dependency of "tslib" @ "^1.10.0".
                  Package "@angular/service-worker" has a missing peer dependency of "tslib" @ "^1.10.0".
    Updating package.json with dependency @angular/cli @ "9.0.0-rc.5" (was "8.3.20")...
    Updating package.json with dependency @angular/core @ "9.0.0-rc.5" (was "8.2.14")...
    Updating package.json with dependency @angular/compiler-cli @ "9.0.0-rc.5" (was "8.2.14")...
    Updating package.json with dependency @angular/language-service @ "9.0.0-rc.5" (was "8.2.14")...
    Updating package.json with dependency @angular-devkit/build-angular @ "0.900.0-rc.5" (was "0.803.20")...
    Updating package.json with dependency @angular/compiler @ "9.0.0-rc.5" (was "8.2.14")...
    Updating package.json with dependency @angular/common @ "9.0.0-rc.5" (was "8.2.14")...
    Updating package.json with dependency @angular/animations @ "9.0.0-rc.5" (was "8.2.14")...
    Updating package.json with dependency @angular/platform-browser @ "9.0.0-rc.5" (was "8.2.14")...
    Updating package.json with dependency @angular/forms @ "9.0.0-rc.5" (was "8.2.14")...
    Updating package.json with dependency @angular/router @ "9.0.0-rc.5" (was "8.2.14")...
    Updating package.json with dependency @angular/platform-browser-dynamic @ "9.0.0-rc.5" (was "8.2.14")...
    Updating package.json with dependency @angular/service-worker @ "9.0.0-rc.5" (was "8.2.14")...
    Updating package.json with dependency typescript @ "3.6.4" (was "3.5.3")...
UPDATE package.json (5246 bytes)
βœ” Packages installed successfully.
** Executing migrations of package '@angular/cli' **

❯ Angular Workspace migration.
  Update an Angular CLI workspace to version 9.
UPDATE angular.json (8832 bytes)
UPDATE ngsw-config.json (1508 bytes)
UPDATE src/tsconfig.app.json (380 bytes)
UPDATE package.json (5243 bytes)
βœ” Packages installed successfully.
  Migration completed.

❯ Lazy loading syntax migration.
  Update lazy loading syntax to use dynamic imports.
  Migration completed.

An unhandled exception occurred: Cannot find module '@angular-devkit/schematics'
Require stack:
- /Users/konradcerny/Sites/Erento/frontend-som/node_modules/@angular/core/schematics/migrations/move-document/index.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular-devkit/schematics/tools/index.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular/cli/utilities/json-schema.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular/cli/models/command-runner.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular/cli/lib/cli/index.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular/cli/lib/init.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular/cli/bin/ng
See "/private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/ng-PMjFIi/angular-errors.log" for further details.

The angular-errors.log file content:


[error] Error: Cannot find module '@angular-devkit/schematics'
Require stack:
- /Users/konradcerny/Sites/Erento/frontend-som/node_modules/@angular/core/schematics/migrations/move-document/index.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular-devkit/schematics/tools/index.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular/cli/utilities/json-schema.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular/cli/models/command-runner.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular/cli/lib/cli/index.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular/cli/lib/init.js
- /private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular/cli/bin/ng
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:794:15)
    at Function.Module._load (internal/modules/cjs/loader.js:687:27)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at /Users/konradcerny/Sites/Erento/frontend-som/node_modules/@angular/core/schematics/migrations/move-document/index.js:19:26
    at /Users/konradcerny/Sites/Erento/frontend-som/node_modules/@angular/core/schematics/migrations/move-document/index.js:10:17
    at Object.<anonymous> (/Users/konradcerny/Sites/Erento/frontend-som/node_modules/@angular/core/schematics/migrations/move-document/index.js:16:3)
    at Module._compile (internal/modules/cjs/loader.js:956:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
    at Module.load (internal/modules/cjs/loader.js:812:32)
    at Function.Module._load (internal/modules/cjs/loader.js:724:14)
    at Module.require (internal/modules/cjs/loader.js:849:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at new ExportStringRef (/private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular-devkit/schematics/tools/export-ref.js:18:25)
    at NodeModulesEngineHost._resolveReferenceString (/private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:58:21)
    at NodeModulesEngineHost.createSchematicDescription (/private/var/folders/zl/ltj48w2n2hgcptmp_fh69mkm0000gn/T/.ng-temp-packages-qjhg0F/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:173:34)

🌍 Your Environment


Angular CLI: 8.3.20
Node: 12.12.0
OS: darwin x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.20
@angular-devkit/build-angular     0.803.20
@angular-devkit/build-optimizer   0.803.20
@angular-devkit/build-webpack     0.803.20
@angular-devkit/core              8.3.20
@angular-devkit/schematics        8.3.20
@angular/cli                      8.3.20
@angular/pwa                      0.803.20
@ngtools/webpack                  8.3.20
@schematics/angular               8.3.20
@schematics/update                0.803.20
rxjs                              6.5.3
typescript                        3.5.3
webpack                           4.39.2

I will try to be as helpful as possible, but no clue what more data I could provide atm.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 7
  • Comments: 22 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Same issue with @angular/material

$ ng update @angular/material
Using package manager: 'npm'
Collecting installed dependencies...
Found 37 dependencies.
Fetching dependency metadata from registry...
    Updating package.json with dependency @angular/material @ "9.0.0" (was "8.2.3")...
    Updating package.json with dependency @angular/cdk @ "9.0.0" (was "8.2.3")...
UPDATE package.json (1592 bytes)
βœ” Packages installed successfully.
An unhandled exception occurred: Cannot find module '@schematics/angular/utility/ast-utils'
Require stack:
- /home/awhite/Code/MyHome/node_modules/@angular/cdk/schematics/utils/ast.js
- /home/awhite/Code/MyHome/node_modules/@angular/cdk/schematics/utils/index.js
- /home/awhite/Code/MyHome/node_modules/@angular/cdk/schematics/index.js
- /home/awhite/Code/MyHome/node_modules/@angular/material/schematics/ng-update/index.js
- /home/awhite/Code/MyHome/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /home/awhite/Code/MyHome/node_modules/@angular-devkit/schematics/tools/index.js
- /home/awhite/Code/MyHome/node_modules/@angular/cli/utilities/json-schema.js
- /home/awhite/Code/MyHome/node_modules/@angular/cli/models/command-runner.js
- /home/awhite/Code/MyHome/node_modules/@angular/cli/lib/cli/index.js
- /home/awhite/.nvm/versions/node/v12.14.1/lib/node_modules/@angular/cli/lib/init.js
- /home/awhite/.nvm/versions/node/v12.14.1/lib/node_modules/@angular/cli/bin/ng
See "/tmp/ng-UxebB2/angular-errors.log" for further details.

Fixed by npm i @schematics/angular before update

@clydin , I tried this advice:

[try] removing both the node_modules folder and the package-lock.json file and then re-installing the packages (npm install)?

But still get the error.

https://stackoverflow.com/a/58111309 I tried just: npm i @angular-devkit/schematics

β–Έ Angular Workspace migration.
  Update an Angular CLI workspace to version 9.
    Package "@angular-devkit/schematics" found in the workspace package.json. This package typically does not need to be installed manually. If it is not being used by project code, it can be removed from the package.json.
UPDATE angular.json (4020 bytes)
UPDATE tsconfig.app.json (272 bytes)
UPDATE package.json (1555 bytes)
βœ” Packages installed successfully.
  Migration completed.

β–Έ Lazy loading syntax migration.
  Update lazy loading syntax to use dynamic imports.
  Migration completed.

An unhandled exception occurred: Cannot find module '@angular-devkit/core'
Require stack:
- /home/awhite/Code/MyHome/node_modules/@angular/core/schematics/utils/project_tsconfig_paths.js
- /home/awhite/Code/MyHome/node_modules/@angular/core/schematics/migrations/move-document/index.js
- /tmp/.ng-temp-packages-ubnNgz/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /tmp/.ng-temp-packages-ubnNgz/node_modules/@angular-devkit/schematics/tools/index.js
- /tmp/.ng-temp-packages-ubnNgz/node_modules/@angular/cli/utilities/json-schema.js
- /tmp/.ng-temp-packages-ubnNgz/node_modules/@angular/cli/models/command-runner.js
- /tmp/.ng-temp-packages-ubnNgz/node_modules/@angular/cli/lib/cli/index.js
- /tmp/.ng-temp-packages-ubnNgz/node_modules/@angular/cli/lib/init.js
- /tmp/.ng-temp-packages-ubnNgz/node_modules/@angular/cli/bin/ng
See "/tmp/ng-g6oHQs/angular-errors.log" for further details.

Reset again, installed core too: npm i @angular-devkit/core

Update succeeds, with commentary on these packages:

β–Έ Angular Workspace migration.
  Update an Angular CLI workspace to version 9.
    Package "@angular-devkit/schematics" found in the workspace package.json. This package typically does not need to be installed manually. If it is not being used by project code, it can be removed from the package.json.
    Package "@angular-devkit/core" found in the workspace package.json. This package typically does not need to be installed manually. If it is not being used by project code, it can be removed from the package.json.

@blogcraft Have a look here at the commit to address this

https://github.com/clydin/angular-cli/commit/5d6602161b3151da7330c3854c9c7cce4c291f12

Effectively temporarily installing β€˜@angular-devkit/schematicsβ€˜ yourself prior to the migrations, then uninstall it after should work

@clydin @alan-agius4 I’m getting this issue updating from Angular 8.2.14 to 9.0 (angular/cli 8.3.25 to 9.0.1)

Should this issue be re-opened, or should I file a new issue? I can provide more details if needed. My project’s fairly simple, I created it with angular/cli@8.2, the only additional dependencies are @angular/material and luxon

$ ng update @angular/cli @angular/core

Your global Angular CLI version (9.0.1) is greater than your local
version (8.3.25). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".
The installed Angular CLI version is older than the latest stable version.
Installing a temporary version to perform the update.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Using package manager: 'npm'
Collecting installed dependencies...
Found 36 dependencies.
Fetching dependency metadata from registry...
    Updating package.json with dependency @angular/cli @ "9.0.1" (was "8.3.25")...
    Updating package.json with dependency @angular/core @ "9.0.0" (was "8.2.14")...
    Updating package.json with dependency @angular-devkit/build-angular @ "0.900.1" (was "0.803.25")...
    Updating package.json with dependency @angular/compiler-cli @ "9.0.0" (was "8.2.14")...
    Updating package.json with dependency @angular/language-service @ "9.0.0" (was "8.2.14")...
    Updating package.json with dependency @angular/common @ "9.0.0" (was "8.2.14")...
    Updating package.json with dependency @angular/router @ "9.0.0" (was "8.2.14")...
    Updating package.json with dependency @angular/forms @ "9.0.0" (was "8.2.14")...
    Updating package.json with dependency @angular/animations @ "9.0.0" (was "8.2.14")...
    Updating package.json with dependency zone.js @ "0.10.2" (was "0.9.1")...
    Updating package.json with dependency typescript @ "3.7.5" (was "3.5.3")...
    Updating package.json with dependency @angular/platform-browser-dynamic @ "9.0.0" (was "8.2.14")...
    Updating package.json with dependency @angular/compiler @ "9.0.0" (was "8.2.14")...
    Updating package.json with dependency @angular/platform-browser @ "9.0.0" (was "8.2.14")...
    Updating package.json with dependency @angular/service-worker @ "9.0.0" (was "8.2.14")...
UPDATE package.json (1541 bytes)
βœ” Packages installed successfully.
** Executing migrations of package '@angular/cli' **

β–Έ Angular Workspace migration.
  Update an Angular CLI workspace to version 9.
UPDATE angular.json (4020 bytes)
UPDATE tsconfig.app.json (272 bytes)
UPDATE package.json (1511 bytes)
βœ” Packages installed successfully.
  Migration completed.

β–Έ Lazy loading syntax migration.
  Update lazy loading syntax to use dynamic imports.
  Migration completed.

An unhandled exception occurred: Cannot find module '@angular-devkit/schematics'
Require stack:
- /home/awhite/Code/MyHome/node_modules/@angular/core/schematics/migrations/move-document/index.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular-devkit/schematics/tools/index.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular/cli/utilities/json-schema.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular/cli/models/command-runner.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular/cli/lib/cli/index.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular/cli/lib/init.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular/cli/bin/ng
See "/tmp/ng-681DTk/angular-errors.log" for further details.

/tmp/ng-681DTk/angular-errors.log

[error] Error: Cannot find module '@angular-devkit/schematics'
Require stack:
- /home/awhite/Code/MyHome/node_modules/@angular/core/schematics/migrations/move-document/index.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular-devkit/schematics/tools/index.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular/cli/utilities/json-schema.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular/cli/models/command-runner.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular/cli/lib/cli/index.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular/cli/lib/init.js
- /tmp/.ng-temp-packages-18FkAV/node_modules/@angular/cli/bin/ng
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
    at Function.Module._load (internal/modules/cjs/loader.js:686:27)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at /home/awhite/Code/MyHome/node_modules/@angular/core/schematics/migrations/move-document/index.js:19:26
    at /home/awhite/Code/MyHome/node_modules/@angular/core/schematics/migrations/move-document/index.js:10:17
    at Object.<anonymous> (/home/awhite/Code/MyHome/node_modules/@angular/core/schematics/migrations/move-document/index.js:16:3)
    at Module._compile (internal/modules/cjs/loader.js:955:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at new ExportStringRef (/tmp/.ng-temp-packages-18FkAV/node_modules/@angular-devkit/schematics/tools/export-ref.js:18:25)
    at NodeModulesEngineHost._resolveReferenceString (/tmp/.ng-temp-packages-18FkAV/node_modules/@angular-devkit/schematics/tools/node-module-engine-host.js:58:21)
    at NodeModulesEngineHost.createSchematicDescription (/tmp/.ng-temp-packages-18FkAV/node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:173:34)

Reset my project to show state before:
git reset --hard; rm node_modules; npm i ng version

Angular CLI: 8.3.25
Node: 12.14.1
OS: linux x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.803.25
@angular-devkit/build-angular     0.803.25
@angular-devkit/build-optimizer   0.803.25
@angular-devkit/build-webpack     0.803.25
@angular-devkit/core              8.3.22
@angular-devkit/schematics        8.3.22
@angular/cdk                      8.2.3
@angular/cli                      8.3.25
@angular/material                 8.2.3
@angular/pwa                      0.803.22
@ngtools/webpack                  8.3.25
@schematics/angular               8.3.22
@schematics/update                0.803.25
rxjs                              6.5.4
typescript                        3.5.3
webpack                           4.39.2

$ npm ls @angular-devkit/schematics

my-home@0.0.0 /home/awhite/Code/MyHome
β”œβ”€β”¬ @angular/cli@8.3.25
β”‚ β”œβ”€β”€ @angular-devkit/schematics@8.3.25 
β”‚ β”œβ”€β”¬ @schematics/angular@8.3.25
β”‚ β”‚ └── @angular-devkit/schematics@8.3.25  deduped
β”‚ └─┬ @schematics/update@0.803.25
β”‚   └── @angular-devkit/schematics@8.3.25 
└─┬ @angular/pwa@0.803.22
  β”œβ”€β”€ @angular-devkit/schematics@8.3.22 
  └─┬ @schematics/angular@8.3.22
    └── @angular-devkit/schematics@8.3.22  deduped

in our case, unfortunately, only the following files have been changed:

	modified:   angular.json
	modified:   ngsw-config.json
	modified:   package-lock.json
	modified:   package.json
	modified:   src/tsconfig.app.json

and I believe there should be also other files modified in regards to ivy & other changes in v9