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

会有一股神秘感。 提交于 2020-05-15 05:49:21

问题


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.


回答1:


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"
  ]



回答2:


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

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



来源:https://stackoverflow.com/questions/47556819/firebase-admin-package-typescript-error-in-cloud-functions-firestore-types-go

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!