Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase @google-cloud/firestore package Typescript error Duplicate identifier 'DocumentData'

I'm using firebase cloud functions using Typescript and every thing works fine. At my code i make one of variables of type DocumentReference and GeoPoint that's make vs code to import it

import { GeoPoint, DocumentReference } from '@google-cloud/firestore'

function offsetSlightly(location:GeoPoint) {
     //some code here
  return new GeoPoint(latitude, longitude)
}

So i need to add that node module i added using command

npm install @google-cloud/firestore

And every thing looks fine when i try to deploy i get a lot of Duplicate identifier eg DocumentData, UpdateData, GeoPoint ..etc

Error:

node_modules/firebase-admin/node_modules/@google-cloud/firestore/types/firestore.d.ts:28:15 - error TS2300: Duplicate identifier 'DocumentData'.


28   export type DocumentData = {[field: string]: any};

That's my package.json {

  "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": {
    "@google-cloud/firestore": "^0.14.1",
    "firebase-admin": "^5.12.1",
    "firebase-functions": "^1.0.4",
    "nodemailer": "^4.6.4",
    "twilio": "^3.16.0"
  },
  "devDependencies": {
    "tslint": "^5.10.0",
    "typescript": "^2.9.2"
  },
  "private": true
}

I don't know the problem but i think it's some conflict in packages.I'm android developer have a little experience in Node. Any help?

like image 824
Ahmed Abdelmeged Avatar asked Jun 20 '18 11:06

Ahmed Abdelmeged


2 Answers

Instead of importing the classes from the standalone Firestore SDK just create type aliases on Firebase Admin SDK's Firestore:

import * as admin from 'firebase-admin';

type GeoPoint = admin.firestore.GeoPoint
type DocumentReference = admin.firestore.DocumentReference
like image 182
Vasil Garov Avatar answered Nov 07 '22 00:11

Vasil Garov


You are using the wrong imports.

In cloud functions you can use admin SDK to get data from Firestore.

Here is an example of adding a GeoPoint in a collection admin.firestore().collection('mycollection').add({ location:new admin.firestore.GeoPoint(1.0, 1.0) });

And this is the import statement

import * as admin from 'firebase-admin';

For more info - https://firebase.google.com/docs/admin/setup

like image 3
Devakanta Rao Avatar answered Nov 06 '22 22:11

Devakanta Rao