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

Created on 14 Sep 2018  路  28Comments  路  Source: firebase/firebase-admin-node

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

Most helpful comment

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

All 28 comments

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

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

Had the same issue. This fixed it for me:

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

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

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`

I have the same problem with the newest packages.

I have the same issue here :)

Having the same issue

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

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 man, have a nice cup of coffee, and if I can help, I will !

Some news about this issue ?

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

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

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"

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

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

>

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.

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

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 = '[email protected]';
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

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

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

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

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)

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

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.

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

Was this page helpful?
0 / 5 - 0 ratings