Cannot install ngx-cookie-service in angular project

1.1k views Asked by At

I am working on an angular project in where I need to use cookies. I am installing ngx-cookie-service module from https://www.npmjs.com/package/ngx-cookie-service But the module is not being installed, its showing the following errors

npm WARN config global --global, --local are deprecated. Use --location=global instead.

npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: [email protected] npm ERR! Found: @angular/[email protected] npm ERR! node_modules/@angular/common npm ERR! @angular/common@"~11.1.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer @angular/common@"^15.0.0" from [email protected]
npm ERR! node_modules/ngx-cookie-service npm ERR!
ngx-cookie-service@"*" 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. npm ERR! npm ERR! See C:\Users\Deepak Mane\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in: npm ERR!
C:\Users\Deepak Mane\AppData\Local\npm-cache_logs\2023-01-01T13_59_03_695Z-debug-0.log

please suggest me a way to use cookie services.

2

There are 2 answers

0
ChopStick On BEST ANSWER

Try

npm install [email protected]

You need to align the library version with the angular version used in your project. You can find the proper version on the page you linked in your question.

0
Sheikh Wahab Mahmood On

For version <9.x.x:

npm install [email protected]

Do not use --force, or --legacy-peer-deps as it will make your web application unstable.

After that in app.module.ts import these:

import { CookieService } from 'ngx-cookie-service';

providers: [
  CookieService
],

If it still does not work then delete node_modules and npm install it again.