Facing error while installing firebase via npm | Unexpected end of JSON input while parsing near

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

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.