angular-cli: An unhandled exception occurred: Cannot find module '@angular-devkit/core'

🐞 Bug report

Command (mark with an x)

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

Is this a regression?

Description

Update my project from angular cli 8.3.25 to latest version

πŸ”¬ Minimal Reproduction

ng update @angular/cli @angular/core

πŸ”₯ Exception or Error




[error] Error: Cannot find module '@angular-devkit/core'
Require stack:
- C:\Users\Giacomo\Documents\Progetti\Angular\forMca\node_modules\@angular\core\schematics\utils\project_tsconfig_paths.js
- C:\Users\Giacomo\Documents\Progetti\Angular\forMca\node_modules\@angular\core\schematics\migrations\move-document\index.js
- C:\Users\Giacomo\AppData\Local\Temp\.ng-temp-packages-4EE2gk\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\tools\export-ref.js
- C:\Users\Giacomo\AppData\Local\Temp\.ng-temp-packages-4EE2gk\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\tools\index.js
- C:\Users\Giacomo\AppData\Local\Temp\.ng-temp-packages-4EE2gk\node_modules\@angular\cli\utilities\json-schema.js
- C:\Users\Giacomo\AppData\Local\Temp\.ng-temp-packages-4EE2gk\node_modules\@angular\cli\models\command-runner.js
- C:\Users\Giacomo\AppData\Local\Temp\.ng-temp-packages-4EE2gk\node_modules\@angular\cli\lib\cli\index.js
- C:\Users\Giacomo\AppData\Local\Temp\.ng-temp-packages-4EE2gk\node_modules\@angular\cli\lib\init.js
- C:\Users\Giacomo\AppData\Local\Temp\.ng-temp-packages-4EE2gk\node_modules\@angular\cli\bin\ng
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at C:\Users\Giacomo\Documents\Progetti\Angular\forMca\node_modules\@angular\core\schematics\utils\project_tsconfig_paths.js:19:20
    at C:\Users\Giacomo\Documents\Progetti\Angular\forMca\node_modules\@angular\core\schematics\utils\project_tsconfig_paths.js:10:17
    at Object.<anonymous> (C:\Users\Giacomo\Documents\Progetti\Angular\forMca\node_modules\@angular\core\schematics\utils\project_tsconfig_paths.js:16:3)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1040:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at C:\Users\Giacomo\Documents\Progetti\Angular\forMca\node_modules\@angular\core\schematics\migrations\move-document\index.js:22:38
    at C:\Users\Giacomo\Documents\Progetti\Angular\forMca\node_modules\@angular\core\schematics\migrations\move-document\index.js:10:17
    at Object.<anonymous> (C:\Users\Giacomo\Documents\Progetti\Angular\forMca\node_modules\@angular\core\schematics\migrations\move-document\index.js:16:3)

🌍 Your Environment



     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / β–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 9.0.1
Node: 13.7.0
OS: win32 x64

Angular: 9.0.0
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.900.1
@angular-devkit/build-angular      0.900.1
@angular-devkit/build-optimizer    0.900.1
@angular-devkit/build-webpack      0.900.1
@angular-devkit/core               9.0.1 (cli-only)
@angular-devkit/schematics         9.0.1
@angular/cdk                       8.2.3
@angular/cli                       9.0.1
@angular/flex-layout               8.0.0-beta.27
@angular/material                  8.2.3
@angular/material-moment-adapter   8.2.3
@angular/pwa                       <error>
@ngtools/webpack                   9.0.1
@schematics/angular                9.0.1 (cli-only)
@schematics/update                 0.900.1
rxjs                               6.5.4
typescript                         3.7.5
webpack                            4.41.2

Anything else relevant?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 27 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@clydin I solve with second solution:

- Install temporany latest version

npm install -D @schematics/angular @angular-devkit/core @angular-devkit/schematics

- Update angular

ng update @angular/cli @angular/core

- Remove package

npm uninstall @angular-devkit/schematics @schematics/angular @angular-devkit/core

But i don’t know what happen cold be something in global installation angular?

just use npm update and try again

It appears that the package manager is placing some of the dependencies required by the migrations within @angular/core (and potentially @angular/material) in locations that are not resolvable to these migrations.

As a first step to attempt to remedy the situation, can you try the following:

  1. Remove @angular-devkit/schematics from the package.json
  2. Delete the node_modules directory and any associated lock files (package-lock.json or yarn.lock)
  3. reinstall (npm install or equivalent for your package manager)
  4. commit the new lock file and try the update

If this does not work then you may need to temporarily install the latest versions of @schematics/angular, @angular-devkit/core, and @angular-devkit/schematics prior to the update. And then remove them afterwards. (npm install -D @schematics/angular/npm install -D @angular-devkit/core/npm install -D @angular-devkit/schematics).

Just got the same issue, upgrading from version 10.0.8 to latest 11.0.2 @clydin 's solution worked (the second one: npm install --save-dev @schematics/angular @angular-devkit/core @angular-devkit/schematics, then doing the ng update @angular/cli @angular/core, and then uninstalling those 3 above)

And now I get more files updated by the migration (in my case: all the spec files - it adds waitForAsync - and the main/root routing config - it adds relativeLinkResolution: 'legacy'). Before, with the error, it was only updating tsconfig files of apps and libs and the angular.json file

An unhandled exception occurred: Cannot find module β€˜@angular-devkit/build-angular/package.json’ Require stack:

  • C:\Users\ELI\AppData\Roaming\npm\node_modules@angular\cli\node_modules@angular-devkit\architect\node\node-modules-architect-host.js
  • C:\Users\ELI\AppData\Roaming\npm\node_modules@angular\cli\node_modules@angular-devkit\architect\node\index.js
  • C:\Users\ELI\AppData\Roaming\npm\node_modules@angular\cli\models\architect-command.js
  • C:\Users\ELI\AppData\Roaming\npm\node_modules@angular\cli\commands\serve-impl.js
  • C:\Users\ELI\AppData\Roaming\npm\node_modules@angular\cli\node_modules@angular-devkit\schematics\tools\export-ref.js
  • C:\Users\ELI\AppData\Roaming\npm\node_modules@angular\cli\node_modules@angular-devkit\schematics\tools\index.js
  • C:\Users\ELI\AppData\Roaming\npm\node_modules@angular\cli\utilities\json-schema.js
  • C:\Users\ELI\AppData\Roaming\npm\node_modules@angular\cli\models\command-runner.js
  • C:\Users\ELI\AppData\Roaming\npm\node_modules@angular\cli\lib\cli\index.js
  • C:\Users\ELI\AppData\Roaming\npm\node_modules@angular\cli\lib\init.js
  • C:\Users\ELI\AppData\Roaming\npm\node_modules@angular\cli\bin\ng See β€œC:\Users\ELI\AppData\Local\Temp\ng-zTY9Wo\angular-errors.log” for further details.

issue solved TY toso82 unistalling and updating pakage did the trick for me

I had this issue: Error: Cannot find module β€˜@angular-devkit/build-angular/package.json’ Just typing:

npm cache clean --force

npm install

It works.

You can run the command below

npm install --save-dev @angular-devkit/build-angular

OR check other answers from an unhandled exception occurred: cannot find module β€˜@angular-devkit/build-angular/package.json’

Had this issue today after doing an update. Solution suggested by Toso82 worked.TY.

Had the same issue than @KingDarBoja with schematics. Manually installing the packages and then deleting them as stated by @Toso82 solved my issue