Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase-Admin package Typescript error in Cloud Functions Firestore : @types/googlemaps

I have two projects with similar Cloud Functions setup, both directly using Typescript setup (no Webpack) similar to this example or this one

One of them uses Firestore, other one doesn't. The one that does not use Firestore compiles and deploys with no error.

However the one with Firestore functions gives me this error on tsc compile:

../node_modules/@types/googlemaps/index.d.ts(33,29): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(37,19): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(54,28): error TS2304: Cannot find name 'Node'.
../node_modules/@types/googlemaps/index.d.ts(787,30): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(798,36): error TS2304: Cannot find name 'Node'.
../node_modules/@types/googlemaps/index.d.ts(811,26): error TS2304: Cannot find name 'Node'.
../node_modules/@types/googlemaps/index.d.ts(1135,20): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1136,22): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1137,18): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1138,22): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1139,23): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1140,23): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1141,29): error TS2304: Cannot find name 'Element'.

... and goes on.

These are package.json dependencies:

"dependencies": {
    "@google-cloud/storage": "^1.5.0",
    "axios": "^0.17.1",
    "child-process-promise": "^2.2.1",
    "firebase-admin": "~5.5.1",
    "firebase-functions": "^0.7.3"
  },
  "devDependencies": {
    "typescript": "^2.6.2"
  },

and content of the tsconfig:

{
  "compilerOptions": {
    "lib": ["es6", "es2015.promise"],
    "module": "commonjs",
    "noImplicitAny": false,
    "outDir": "build",
    "sourceMap": true,
    "target": "es6"
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

What am I missing? Is it related to Typescript version? (2.6) Do I need to import a @types? Adding dev-dependency @types/node did not help.

like image 461
Bogac Avatar asked Nov 29 '17 15:11

Bogac


3 Answers

At first I thought problem was exclusion of node_modules folder in tsconfig file and removed "exclude": [ "node_modules" ] part. It did not help.

Then since all errors seems to be related to DOM element names or "Node", it should be about a missing types definition of some general package, hence did another search on that matter and run into this answer of a similar question: Typescript build getting errors from node_modules folder

Changing tsconfig like this (adding reference to lib.es6.d.ts) make my problem go away:

  "include": [
    "src/**/*.ts"
  ],
  "files": [
    "node_modules/typescript/lib/lib.es6.d.ts"
  ],
  "exclude": [
      "node_modules"
  ]
like image 128
Bogac Avatar answered Oct 27 '22 01:10

Bogac


Adding "skipLibCheck": true to tsconfig.json also does the trick.

credit - https://github.com/firebase/firebase-tools/issues/749#issuecomment-385693352

like image 44
Kholofelo Avatar answered Oct 27 '22 00:10

Kholofelo


I had this issue with Firebase functions project. FULL solution for:

node_modules/@google-cloud/firestore/types/firestore.d.ts:1629:8 - error TS2304: Cannot find name 'AsyncIterable'.

  1. Inside your project folder run this in cmd: npm install -g npm-check-updates
  2. Inside your project folder, fo to /functions and run this in cmd: ncu -u Here you'll see something like this:
 firebase-admin            ^9.2.0  →   ^9.5.0
 firebase-functions       ^3.11.0  →  ^3.13.1
 googleapis               ^40.0.0  →  ^67.0.0
 typescript                ^3.8.0  →   ^4.1.5
 firebase-functions-test   ^0.2.0  →   ^0.2.3
  1. Here run in cmd: npm install
  2. At this point, you can try to deploy again, but you could get this error: node_modules/@google-cloud/firestore/types/firestore.d.ts:1638:8 - error TS2583: Cannot find name 'AsyncIterable'. Do you need to change your target library? Try changing the lib compiler option to 'es2018' or later.
  3. In case you get error from prevous step then open file functions/tsconfig.json and update value for target node as it says in error text, in my case I updated to es2018 and deploy should be run fine

p.s. Don't forget to save each change, just Ctrl+S ;)

like image 34
Choletski Avatar answered Oct 26 '22 23:10

Choletski