Ahmed Abdelmeged
Ahmed Abdelmeged

Reputation: 2419

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?

Upvotes: 5

Views: 3663

Answers (3)

Deepam Chakraborty
Deepam Chakraborty

Reputation: 11

I had a same problem. A separate node_modules got created within "functions/node-modules/firebase-admin". I deleted it manually and got it resolved. I hope this might be one of the solutions.

Upvotes: 1

Vasil Garov
Vasil Garov

Reputation: 4931

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

Upvotes: 9

Devakanta Rao
Devakanta Rao

Reputation: 105

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

Upvotes: 3

Related Questions