Search code examples
angularmigration

Angular product update from 12 to 16 failed with missing peer dependencies error


I am working on upgrading the Angular version from 12 to 16. 

Angular migration is failing for missing peer dependencies error if I don't specify the --force with the ng update command.

I executed ng update @angular/core@13 @angular/cli@13 --force command for migrating the application from 12 to 16.

Is it a good practice to use --force with the ng command?

After the successful migration, I will need to deploy the changes on the server.

I will also need to execute --force on the server. Is it a good practice?

If it is not a good practice, then we need help with the Angular migration failing issue solution.

I executed the following commands for completing the Angular version migration without issues.

  1. ng update @angular/core@13 @angular/cli@13 --force
  2. ng update @angular/core@14 @angular/cli@14 --force
  3. ng update @angular/[email protected] @angular/[email protected] --force
  4. ng update @angular/[email protected] @angular/[email protected]
  5. npm install --force

Solution

  • Using the --force option should only be used if you know its only a peer dependency warning with an older package that's still compatible with an updated version of Angular.

    Even after you upgrade the packages that way, you may still run into peer dependency errors when using npm install. In that case, you want to add a .npmrc file at the root of your project with the legacy-peer-deps=true flag in it. This bypasses the peer dependency errors.

    https://docs.npmjs.com/cli/v7/using-npm/config#legacy-peer-deps

    Ultimately, you still need to validate that the packages you depend on work with the latest version of Angular you're upgrading to. Upgrading one major at a time is always recommended.