7

I am trying to install firebase in my fresh react project, I could not able to install it.

Whether it is an error or the npm is taking time. I am waiting for more than half an hour.

enter image description here enter image description here

VnoitKumar
  • 1,350
  • 15
  • 29

2 Answers2

19

Try this (you may need to run sudo or if you're on Windows, open cmd as Admin)..

npm cache clean --force

then run

npm install firebase
Matt Oestreich
  • 8,219
  • 3
  • 16
  • 41
  • 1
    This worked perfectly a year later. Reading up on this, npm cache is self healing, so would be nice to know *why* this is the solution! :D – frackham Nov 04 '20 at 23:58
  • 2
    It looks like this happens when NPM cache becomes corrupt. It doesn't happen just for firebase. I honestly can't seem to find a clear answer on why. May be worth opening another question - it may serve as a good resource down the line (as there doesn't appear to be anything clear online right now). – Matt Oestreich Nov 05 '20 at 05:04
2

while the above answer seems to work for most cases it wasn't true for my case. I tried

npm cache clean -f
npm install firebase

no luck!

I followed this thread which explained a lot about npm caches which also concluded the above method should work and maybe to just verify cache before installing firebase

   npm cache clean -f
   npm install firebase
   npm verify cache

still, no luck so I just decided to add it in package.json as a dependency with the latest stable version of firebase (8.0.0) at this time.

so go to package.json file and in the dependencies section

"dependencies": {
     "firebase": "^8.0.0",
     ...other dependencies
     }

and do

npm cache clean -f
npm install npm@latest

this should work for similar cases check out this link to see how caching on npm works in detail.