angular-cli: Migration failed: Cannot read property 'Loose' of undefined

🐞 Bug report

Command (mark with an x)

ng update @angular/cli --from 8 --to 9 --migrate-only

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • [ x] update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, the previous version in which this bug was not present was: Migrating from angular 7 to 8

Description

** Executing migrations of package β€˜@angular/cli’ **

Replace deprecated β€˜styleext’ and β€˜spec’ Angular schematic options. Γ— Migration failed: Cannot read property β€˜Loose’ of undefined

πŸ”¬ Minimal Reproduction

I can only reproduce it on this one project I’ve upgraded another angular project without any issues

πŸ”₯ Exception or Error



[error] TypeError: Cannot read property 'Loose' of undefined
    at readJsonFileAsAstObject (~\node_modules\@angular\cli\node_modules\@schematics\angular\migrations\update-9\utils.js:90:74)
    at Object.getWorkspace (~\node_modules\@angular\cli\node_modules\@schematics\angular\migrations\update-9\utils.js:77:21)
    at ~\node_modules\@angular\cli\node_modules\@schematics\angular\migrations\update-9\schematic-options.js:15:35
    at MergeMapSubscriber.project ({userDir}\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\src\rules\call.js:75:24)
    at MergeMapSubscriber._tryNext ({userDir}\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\operators\mergeMap.js:67:27)
    at MergeMapSubscriber._next ({userDir}\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\operators\mergeMap.js:57:18)
    at MergeMapSubscriber.Subscriber.next ({userDir}\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Subscriber.js:66:18)
    at Observable._subscribe ({userDir}\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\util\subscribeToArray.js:5:20)
    at Observable._trySubscribe ({userDir}\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:44:25)
    at Observable.subscribe ({userDir}\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:30:22)

🌍 Your Environment



Angular CLI: 10.2.3
Node: 14.18.1
OS: win32 x64

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

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.13.10
@angular-devkit/build-angular      0.1002.3
@angular-devkit/core               7.3.10
@angular-devkit/schematics         10.2.3
@angular/cdk                       10.2.7
@angular/cli                       10.2.3
@angular/material                  10.2.7
@angular/material-moment-adapter   10.2.7
@schematics/angular                7.3.10
@schematics/update                 0.13.10
rxjs                               7.4.0
typescript                         3.9.10

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 32

Most upvoted comments

Hi, I think when you run npx @angular/cli@9 update @angular/core@9 @angular/cli@9, it supposes to install the @angular/cli@9 in your local node_modules and run update command against that version. For some reason it is not happening as expected.

These are the steps that I followed and I was able to migrate Angular 8 application to Angular 9 without any errors.

  1. Make sure your project is clean (delete node_modules and package-lock.json file if required and do a fresh npm install)
  2. Install target @angular/cli version in your local (in this case run npm install -D @angular/cli@9)
  3. Now run update command against the local cli (npx ng update @angular/core@9 @angular/cli@9 - you might need to use --force and --allow-dirty based on your project)

This should migrate your application successfully to the target version.

(My Node Version v12.20.1, NPM is 6.13.4, Global ng version is 8.3.25 )

I was able to replicate this issue. As a workaround you can use the following command.

NG_DISABLE_VERSION_CHECK=1 ./node_modules/.bin/ng update @angular/cli --from 8 --to 9 --migrate-only

Thanks for reporting this issue. Luckily, it has already been fixed in one of the recent releases.