firebase / firebase-admin-node

Firebase Admin Node.js SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
1.63k stars 371 forks source link

typescript definitions conflict with v6.0.0 & @google-cloud/storage and @google-cloud/firestore #358

Closed ovaris closed 5 years ago

ovaris commented 6 years ago

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
google-oss-bot commented 6 years ago

I found a few problems with this issue:

ovaris commented 6 years ago

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';
vdiaz1130 commented 6 years ago

Had the same issue. This fixed it for me:

npm i @google-cloud/storage@latest --save

ckmluna2 commented 6 years ago

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

minstn commented 6 years ago

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`

juliamazur commented 6 years ago

I have the same problem with the newest packages.

Meg4mi commented 6 years ago

I have the same issue here :)

rubio05 commented 6 years ago

Having the same issue

theoafactor commented 6 years ago

I have the same issue. Backward versions don't seem to help

lupas commented 6 years ago

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.

gtcdevop commented 6 years ago

Same man, have a nice cup of coffee, and if I can help, I will !

Jbz797 commented 6 years ago

Some news about this issue ?

mlejva commented 6 years ago

Also having same issue. Shouldn't this be given higher priority since it's basically breaking Typescript build?

mlejva commented 6 years ago

I opened new issue at google-cloud/storage repo - here

otnielgomez commented 6 years ago

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"

lupas commented 6 years ago

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

mlejva commented 6 years ago

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'.
lupas commented 6 years ago

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'.

Using typescript, I'm doing:

import * as admin from 'firebase-admin'
const storage = admin.storage()

Which threw the error mentioned above before, but since v2.1.0 it works again for me.

ovaris commented 6 years ago

@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.

ovaris commented 6 years ago

Created a PR https://github.com/firebase/firebase-admin-node/pull/368

kmturley commented 6 years ago

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

rodleviton commented 6 years ago

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%20notes/TypeScript%202.0.md#new---skiplibcheck

hiranya911 commented 5 years ago

This upgrade has been scheduled for the next major release. We are working internally to figure out the timeline.

JTR-Wang commented 5 years ago

Hi In my project, i also have the same issue. and i solve it, like this. I hope this can help you image

I have not use @google-cloud/firestore

dinvlad commented 5 years ago

Having the same issue with @google-cloud/firestore v0.20.0 upwards (v0.19.0 works fine). Is there any update on when it's resolved?

(OT here, but we have to resort to using @google-cloud/firestore only because of the timestampsInSnapshots warning)

hiranya911 commented 5 years ago

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

Mikkelet commented 4 years ago

Im having this problem now. What's weirder is, I am using the EXACT same dependencies for the project thats tied to a test firestore database and IT has no problem deploying the functions. So weird.

whaatt commented 4 years ago

@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.