firebase-admin-node: typescript definitions conflict with v6.0.0 & @google-cloud/storage and @google-cloud/firestore

Hi,

I have a project which uses firebase-admin & @google-cloud/storage and @google-cloud/firestore. After upgrading to firebase-admin v6.0.0 I get following typescript errors:

node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: DocumentData, UpdateData, Firestore, GeoPoint, Transaction, WriteBatch, WriteResult, DocumentReference, DocumentSnapshot, QueryDocumentSnapshot, OrderByDirection, WhereFilterOp, Query, QuerySnapshot, DocumentChangeType, CollectionReference, FieldValue, FieldPath, Timestamp, FirebaseFirestore

23 declare namespace FirebaseFirestore {
   ~~~~~~~

  node_modules/firebase-admin/node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1
    23 declare namespace FirebaseFirestore {
       ~~~~~~~
    Conflicts are in this file.

node_modules/@google-cloud/firestore/types/firestore.d.ts:79:5 - error TS2374: Duplicate string index signature.

79     [key: string]: any; // Accept other properties, such as GRPC settings.
       ~~~~~~~~~~~~~~~~~~~

node_modules/firebase-admin/lib/index.d.ts:18:9 - error TS2305: Module '"/Users/ovaris/programming/fs-server/node_modules/@google-cloud/storage/build/src/index"' has no exported member 'Bucket'.

18 import {Bucket} from '@google-cloud/storage';
           ~~~~~~

node_modules/firebase-admin/node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: DocumentData, UpdateData, Firestore, GeoPoint, Transaction, WriteBatch, WriteResult, DocumentReference, DocumentSnapshot, QueryDocumentSnapshot, OrderByDirection, WhereFilterOp, Query, QuerySnapshot, DocumentChangeType, CollectionReference, FieldValue, FieldPath, Timestamp, FirebaseFirestore

23 declare namespace FirebaseFirestore {
   ~~~~~~~

  node_modules/@google-cloud/firestore/types/firestore.d.ts:23:1
    23 declare namespace FirebaseFirestore {
       ~~~~~~~
    Conflicts are in this file

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 16
  • Comments: 28 (2 by maintainers)

Most upvoted comments

I have the same issue here 😃

Actually it seems that culprit seems to be latest 0.17.0 version of @google-cloud/firestore. Also 2.0.3 version of @google-cloud/storage has broke typings:

node_modules/firebase-admin/lib/index.d.ts:18:9 - error TS2305: Module '"...node_modules/@google-cloud/storage/build/src/index"' has no exported member 'Bucket'.

18 import {Bucket} from '@google-cloud/storage';

Having the same issue

@vdiaz1130 This did not seem to help. I’m still getting the same error.

Same issue here. I’m currently sticking with @google-cloud/storage v1.7.0 since an upgrade to v2 breaks with the error that @ovaris is mentioning.

Same problem here:

package versions

node version: v8.12.0

node_modules/firebase-admin/lib/index.d.ts(18,9): error TS2305: Module '"/Users/mstonys/one/one/functions/node_modules/@google-cloud/storage/build/src/index"' has no exported member 'Bucket'. npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! functions@ build: tsc` npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the functions@ build script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! /Users/one/.npm/_logs/2018-09-26T06_11_51_398Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code2`

@Mikkelet Try using exact versions instead of approximate (~ or ^) versions, especially if you haven’t upgraded to @google-cloud/firestore@3.

Thefirebase-admin module may not be using semantic versioning conventions, since the minor bump from 8.8.0 to 8.9.0 depends on a major bump (2.x.x to 3.x.x) for @google-cloud/firestore.

This has been fixed in the master branch, and included in the next major release. See #437 and #451 for progress.

I know it is not pretty but here is a “temporary” workaround to get your code to compile and ignore the conflict. Inside your tsconfig.json add the following:

{
    "compilerOptions": {
        "skipLibCheck": true,
        ...
    },
}

Read more about this option here: https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/release notes/TypeScript 2.0.md#new---skiplibcheck

Isn’t this because firebase admin uses @types/google-cloud__storage:

"firebase-admin": {
     "version": "6.0.0",
     "requires": {
       "@firebase/app": "0.3.4",
       "@firebase/database": "0.3.6",
       "@google-cloud/firestore": "0.16.1",
       "@google-cloud/storage": "1.7.0",
       "@types/google-cloud__storage": "1.7.2",
       "@types/node": "8.10.36",
       "jsonwebtoken": "8.1.0",
       "node-forge": "0.7.4"
     }...

But the package already has it’s own definitions? https://www.npmjs.com/package/@google-cloud/storage https://github.com/googleapis/nodejs-storage/blob/master/src/index.ts

If I do: rm -rf node_modules/@types/google-cloud__storage

then it bypasses the error

UPDATE: Looks like a better potential workaround is to use:

import * as functions from 'firebase-functions';
import * as storage from '@google-cloud/storage';

const client = new storage.Storage({
 projectId: 'xxxx',
});

UPDATE 2: I got it working this different way

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as Handlebars from 'handlebars';
import * as nodemailer from 'nodemailer';

const APP_BUCKET = 'project-id.appspot.com';
const APP_EMAIL = 'noreply@firebase.com';
const APP_NAME = 'Cloud Storage for Firebase quickstart';

const mailTransport = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: functions.config().gmail.email,
    pass: functions.config().gmail.password,
  },
});

export const SendWelcomeEmail = functions.auth.user().onCreate((user) => {
  return sendEmail('emails/signup.html', `Welcome to ${APP_NAME}!`, user);
});

export const SendByeEmail = functions.auth.user().onDelete((user) => {
  return sendEmail('emails/signout.html', `Goodbye from ${APP_NAME}!`, user);
});

async function sendEmail(path, subject, user) {
  const bucket = admin.storage().bucket(APP_BUCKET);
  const template = await bucket.file(path).download();
  const mailOptions = {
    from: `${APP_NAME} <${APP_EMAIL}>`,
    subject: subject,
    html: Handlebars.compile(template.toString())(user),
    to: user.email,
  };
  await mailTransport.sendMail(mailOptions);
  console.log('sendEmail', subject, user.email);
  return true;
}

You can read the related threads here: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/28774 https://github.com/googleapis/nodejs-storage/pull/392 https://github.com/googleapis/nodejs-storage/issues/456

@lupas Issue still remains, you cannot use firebase-admin package together with latest @google-cloud/storage because of TS identifier conflicts . You are using storage from inside firebase-admin which I would not like to do.

seems to work again with the recently released “@google-cloud/storage”: “^2.1.0”, guess this can be closed.

How are you importing Storage?

With

import { Storage } from '@google-cloud/storage';

I’m getting following error

Module '"node_modules/@types/google-cloud__storage/index"' has no exported member 'Storage'.

As a work arround in your /node_modules/firebase-admin/lib/index.d.ts replace:

Line 18 Instead of: import {Bucket} from ‘@google-cloud/storage’;

Use: import {Storage} from ‘@google-cloud/storage’;

AND Line 589

Instead of: bucket(name?: string): Bucket;

Use: bucket(name?: string): Storage;

And where you need to call it use it like this:

const {Storage} = require(‘@google-cloud/storage’); const gcs = new Storage();

It worked for me, im using:

@google-cloud/storage”: “^2.0.3”, “firebase-admin”: “~5.12.1”, “firebase-functions”: “^2.0.5”