5
votes

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?

3
Please edit your question to show the minimal code that reproduces the problem, along with the exact error messages that it generates. Without code, all we can do is guess.Doug Stevenson
I put the code is needed it's package conflict i think. I have a variable location:GeoPoint and to get GeoPoint i need to add google cloud package that what case the problem @DougStevensonAhmed Abdelmeged
You put an import statement, but you're missing the code where those imported types are actually used.Doug Stevenson
OK i added one function @DougStevensonAhmed Abdelmeged
Add the exact error messages also, please. Really, what we need is a full example that reproduces the error.Doug Stevenson

3 Answers

7
votes

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
3
votes

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

1
votes

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.