6

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.

Eliya Cohen
  • 10,716
  • 13
  • 59
  • 116
  • 1
    If everything builds ok with `npm run build`, then the problem lies within webstorm. – Doug Stevenson Oct 24 '18 at 21:03
  • it outputs an error. But it something regarding the parent directory (the app itself), But actually, there's no error at all. I had to change the build script to `tsc --skipLibCheck`. – Eliya Cohen Oct 25 '18 at 11:58
  • I tested with "firebase init" function only. with VS code all good and your package.json has no problem. FYI, firebase-admin module refers @google-cloud/firestore types. I presume your webstorm does not parse properly. – John Oct 31 '18 at 05:37
  • @JohnCho I think the problem has to do with the parent directory and not with the functions folder, since I have the exact same folder in a different app and Webstorm parses it properly – Eliya Cohen Oct 31 '18 at 10:44
  • @Eliya Cohen easier debug way is from simple code. I just confirmed nothing wrong with your package.json file. As you mentioned, webstorm works with others project. Then your code are not compatible with webstorm. Can you provide source code? – John Oct 31 '18 at 12:36
  • I would love to share that source code, but it's signed under NDA. Anyway, I guess I won't find an answer here since I can't elaborate enough to figure out it doesn't work. What I can tell you - the parent folder is ionic 4 project. – Eliya Cohen Oct 31 '18 at 16:41

1 Answers1

0

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

lena
  • 90,154
  • 11
  • 145
  • 150