admin.firestore is not a function when trying to use google cloud functions with node.js

I was able to reproduce the error and brute-force a solution. I don't know much about npm and can't offer a complete explanation of why this solution worked.

My original package.json contained:

  "dependencies": {
    ...
    "firebase-admin": "^4.2.1",
    "firebase-functions": "^0.7.1",
    ...
  },

As recommended in the documentation, I ran these two commands in the functions folder:

npm install -g firebase-tools
npm install firebase-functions@latest --save

I also tried:

npm install --save firebase-admin
npm upgrade

I repeatedly received these error messages:

+-- UNMET PEER DEPENDENCY [email protected]
npm WARN [email protected] requires a peer of firebase-admin@~5.4.2 but none was installed.

I figured firebase-admin needed to be updated but couldn't make it happen. So I edited the dependencies file to delete this line:

"firebase-admin": "^4.2.1"

then ran npm install --save firebase-admin again. With that, the package.json contained version "firebase-admin": "^5.4.2" and var db = admin.firestore(); compiled without error.