angularnpm

Error while using npm install in an angular 13 project


I got stuck in this problem that occurred when i used npm install in the project directory. How can i resolve it ?

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: dss-admin-dashboard-ui@1.0.0-SNAPSHOT
npm ERR! Found: @angular/core@13.3.12
npm ERR! node_modules/@angular/core
npm ERR!   @angular/core@"\~13.3.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/core@"^4.0.0" from ngx-barcode@0.3.0
npm ERR! node_modules/ngx-barcode
npm ERR!   ngx-barcode@"^0.3.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

I tried to resolve the problem by installing another version of ngx-barcode but it didn't work.


Solution

  • This issue occurs because the project uses @angular/core@13.3.12 while ngx-barcode@0.3.0 requires @angular/core@"^4.0.0".

    According to npm the library ngx-barcode only supports Angular 4 (npm) and its last update was over 4 years ago. Making it incompatible with Angular 13 and unlikely to receive further updates.

    You have two solution:

    1. Replace the library with one that supports Angular 13.
    2. Use --legacy-peer-deps as a temporary fix

    I wouldn’t recommend bypassing the issue with --legacy-peer-deps. Instead I’d suggest finding a different library to replace it. Preferably one that is actively maintained to ensure stability when upgrading to future versions such as Angular 18.

    But if replacing it with another library isn’t an option. Use the fix mentioned above in point 2 and hope that everything works as expected.

    EDIT: Here, I found a version of the library that seems to be based on yours and supports Angular 9–18 (ngx-barcode6).