Error in Typescript for Firebase @google-cloud/firestore package: Duplicate declaration of 'DocumentData' identifier

I've been working with Firebase cloud functions in Typescript and everything has been running smoothly. In my code, I declared variables of type DocumentReference and GeoPoint, which prompted VS Code to import them.

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

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

After adding the necessary node module using the command

npm install @google-cloud/firestore

Everything seemed fine, but when trying to deploy, I encountered multiple "Duplicate identifier" errors for DocumentData, UpdateData, GeoPoint, and more.

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};

Here's a snippet from 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'm not sure where the issue lies, but I suspect there might be conflicts in the packages. As an android developer with limited experience in Node, any assistance would be greatly appreciated.

Answer №1

Enhance your code by defining type aliases within Firebase Admin SDK's Firestore rather than importing separate classes from the standalone Firestore SDK:

import * as admin from 'firebase-admin';

type Location = admin.firestore.GeoPoint
type RefDocument = admin.firestore.DocumentReference

Answer №2

Make sure to use the correct imports for your cloud functions.

If you're working with Firestore in cloud functions, you can utilize the admin SDK to interact with the data.

Here is an illustration of how to add a GeoPoint to a collection: admin.firestore().collection('mycollection').add({ location:new admin.firestore.GeoPoint(1.0, 1.0) });

Don't forget to include this import statement: import * as admin from 'firebase-admin';

To learn more, visit - https://firebase.google.com/docs/admin/setup

Answer №3

Dealing with a similar issue, I discovered that a duplicate node_modules directory had appeared within "functions/node-modules/firebase-admin". After removing it myself, the problem was fixed. Hopefully, this information can help as a potential solution to others facing the same problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble triggering a Bootstrap 5 modal using TypeScript

Have you heard the news that Bootstrap 5 has been released? To open a modal using JavaScript, the official website provides the following code: var myModal = new bootstrap.Modal(document.getElementById('myModal'), options) myModal.toggle() Howev ...

When attempting to retrieve the current position using "position.coords.latitude", I receive an undefined value

Having recently started with Ionic2, I came across a helpful tutorial that worked flawlessly for me. The tutorial, which can be found at , demonstrates listing nearby places and calculating the distance between these locations and a hardcoded place in the ...

Struggling with TypeScript compilation in a Vue.js project? Encounter error code TS2352

Here is my code snippet from window.ts import Vue from 'vue' interface BrowserWindow extends Window { app: Vue } const browserWindow = window as BrowserWindow export default browserWindow Encountering a compilation error Error message: TS2 ...

Error encountered with next-auth and the getServerSession function

Whenever I try to use the getServerSesssion function with all the necessary parameters, it results in a type error. In my code, I have the getServerAuthSession function defined as shown below: import { authOptions } from '@/pages/api/auth/[...nextauth ...

Props used in styled components are effective, although they may trigger a warning message stating, "Warning: Received `true` for a non-boolean attribute `cen`."

Caution: A non-boolean attribute "cen" received a value of "true". If you intend to render it in the DOM, provide a string instead: cen="true" or cen={value.toString()}. While using Props in Styled-Component with TypeScript and Material-UI, everything func ...

Error: Model attribute missing in Adonis JS v5 relationship

Recently, I started diving into the Adonis framework (v5) and decided to build a todo list api as part of my learning process. However, I'm facing an issue concerning the relationship between the User and Todo entities. Let me show you the models fo ...

What kind of error should be expected in a Next.js API route handler?

Recently, I encountered an issue with my API route handler: import { NextRequest, NextResponse } from "next/server"; import dbConnect from "@/lib/dbConnect"; import User from "@/models/User"; interface ErrorMessage { mess ...

What is the best way to ensure that a global variable is populated after subscribing to an asynchronous event?

Recently, I encountered an async firebase call that looks something like this: this.fbProvider.fbGetProfile() .subscribe(p => { this.profile = p; ...

Components in Angular 4 that are loaded dynamically using attribute directives are enclosed within a <div> element

My goal is to dynamically generate components based on the configuration options, specifically creating a toolbar with different "toolbar items". Following the Angular guide at: https://angular.io/docs/ts/latest/cookbook/dynamic-component-loader.html, I h ...

Setting an initial value for an @Output EventEmitter in Angular 6 is a breeze

I'm working on a component that includes a dropdown selection menu. <p style="padding: 5px"> <select [(ngModel)]='thisDD' name="nameDD" id="idDD" (ngModelChange)="updateDD(thisDD)" class="form-control"> <o ...

The input field cannot accommodate the lengthy value in the Mat Select option

When a user selects a value in my mat select, it doesn't display well in the selection box. The text wraps when the selection is opened, but once a choice is made, it gets cut off without proper spacing between the ellipses and the dropdown arrow. Th ...

The method getDay is not recognized as a function in Typescript Angular

After searching for a solution, I came across a similar question that did not address the specific issue I am dealing with. The challenge I am facing involves parsing a date into a string. Below is my current implementation: export class DataFormater { ...

Angular 2 routing for dynamic population in a grid system

My website is compiling correctly, however, in the Sprint dropdown menu where I have set up routing... <a *ngFor = "let item of sprint;" routerLink = "/Summary" routerLinkActive = "active"> <button *ngIf = "item.Name" mat-menu-item sty ...

The 'format' property cannot be found on the 'Duration' type

When working with TypeScript and trying to utilize "moment-duration-format", I encountered an issue where webpack is constantly throwing errors stating that it cannot locate the "format" method in this line of code: return moment.duration(value, "minutes" ...

How to effectively send an HTTP GET request to a REST API in Angular 2 and save the response in a JSON object

Currently, I am attempting to execute a GET request to the GitHub API using Angular2. The returned data is in JSON format, and my goal is to store it in a JSON object for further processing. While referring to the Angular2 documentation for guidance, I en ...

Why does tsc produce a compiled file that throws an exception when executed, while ts-node successfully runs the TypeScript file without any issues?

I have written two ts files to test a decorator. Here is the content of index.ts: import { lockMethod } from './dec'; class Person { walk() { console.info(`I am walking`); } @lockMethod run() { console.info(`I am running`); } ...

Updating array content based on property criteria

I've been tackling a project in Angular where I have two arrays set up like this: array1 = [ { Name: "Jack", Id: "1", Location: "UK" }, { Name: "Rose", Id: "2", Location: ...

Get ready for 10 AM with the RxJS timer function

I am trying to figure out how to schedule a method in my code using rxjs/timer. Specifically, I want the method to run at precisely 10 AM after an initial delay of 1 minute. However, my current implementation is running every 2 minutes after a 1-minute d ...

Is there a way to implement a textbox in Aurelia using Typescript that restricts input to only numbers?

I'm looking to create a textbox that only accepts numbers using bindable property instead of oninput. Could someone provide guidance on how to achieve this? textbox.html <template bindable=""> <input style=" box-sizing: border-b ...

What is a mapped Record type in which each key K in Record<T, K> is determined by the value of T?

My previous question from three weeks ago has led to this extension: Set the keys of an interface to the possible values of a different interface? In summary, I have the following type definitions: interface SuccessStatus { type: 'success'; ...