Firebase Cloud Functions TS - Unresolved functions/variables/methods

Viewed 579

I use the IDE WebStorm, and I'm having some difficulties coding the cloud functions. It looks like WebStorm doesn't recognize some methods/ functions/variables of firebase.

Example:

enter image description here

The dark red color means that it couldn't resolve the property. As you can see, it doesn't recognize db.settings, snapshot.data(), db.doc() and snapshot.id.

My package.json (auto-generated, haven't touched anything):

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase serve --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "~6.0.0",
    "firebase-functions": "^2.0.3"
  },
  "devDependencies": {
    "tslint": "~5.8.0",
    "typescript": "~2.8.3"
  },
  "private": true
}

What I tried so far with no success:

  • Invalidate and Restart
  • Reinstall node_modules
  • Cancel exclusion of the package @google-cloud
  • delete functions and firebase init functions - Worked for a moment and then it failed to locate the source.
  • Tried to un-exclude node_modules just for the sake of it.

Unexcluded packages:

  • @google-cloud
  • @types (+ @types/*)
  • firebase-admin
  • firebase-functions
  • tslint
  • typescript

PS - I don't know if it has to do with the parent folder, but I'm using Ionic 4 in this project, while in another project I use only Angular and it behaves well (both functions folders has the exact same settings).

Update 1 - I tried to run this project both on PC and MacOS (different devices) and it happens in both of them. This issue doesn't happen on different projects.

1 Answers

The problem is that FireStore functions are actually declared in @google-cloud/firestore plugin that is installed as a dependency of firebase-admin but not listed in your project package.json. And WebStorm auto-excludes all indirect dependencies from indexing for better performance, so functions definitions are not available to code analyser. To work out the issue, right-click node_modules/@google-cloud folder in your Project tool window and shooe Mark directory as/Not excluded. This should solve the issue:

enter image description here

enter image description here

Related