Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ovaris opened this issue Sep 14, 2018 · 28 comments
Assignees

Comments

@ovaris
Copy link

ovaris commented Sep 14, 2018

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
Copy link

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.

@ovaris
Copy link
Author

ovaris commented Sep 14, 2018

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
Copy link

Had the same issue. This fixed it for me:

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

@ckmluna2
Copy link

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

@minstn
Copy link

minstn commented Sep 26, 2018

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
Copy link

I have the same problem with the newest packages.

@Meg4mi
Copy link

Meg4mi commented Sep 26, 2018

I have the same issue here :)

@rubio05
Copy link

rubio05 commented Sep 26, 2018

Having the same issue

@theoafactor
Copy link

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

@lupas
Copy link

lupas commented Sep 29, 2018

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
Copy link

gtcdevop commented Oct 1, 2018

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

@Jbz797
Copy link

Jbz797 commented Oct 1, 2018

Some news about this issue ?

@mlejva
Copy link

mlejva commented Oct 8, 2018

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

@mlejva
Copy link

mlejva commented Oct 8, 2018

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

@otnielgomez
Copy link

otnielgomez commented Oct 9, 2018

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
Copy link

lupas commented Oct 14, 2018

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

@mlejva
Copy link

mlejva commented Oct 15, 2018

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
Copy link

lupas commented Oct 15, 2018

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
Copy link
Author

ovaris commented Oct 15, 2018

@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
Copy link
Author

ovaris commented Oct 15, 2018

Created a PR #368

@kmturley
Copy link

kmturley commented Oct 18, 2018

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:
DefinitelyTyped/DefinitelyTyped#28774
googleapis/nodejs-storage#392
googleapis/nodejs-storage#456

@rodleviton
Copy link

rodleviton commented Oct 23, 2018

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 hiranya911 self-assigned this Dec 14, 2018
@hiranya911
Copy link
Contributor

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

@JTR-Wang
Copy link

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
Copy link

dinvlad commented Jan 29, 2019

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
Copy link
Contributor

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

@Mikkelet
Copy link

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
Copy link

whaatt commented Jan 13, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests