stripe-firebase-extensions icon indicating copy to clipboard operation
stripe-firebase-extensions copied to clipboard

FirebaseError on createCheckoutSession

Open ElBouhaliMohamed opened this issue 3 years ago • 45 comments

Bug report

  • firestore-stripe-web-sdk

Describe the bug

FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore
    at ba (index.esm2017.js?4515:14943)
    at FirestoreSessionDAO.eval (session.js?995f:116)
    at Generator.next (<anonymous>)
    at eval (session.js?995f:22)
    at new Promise (<anonymous>)
    at __awaiter (session.js?995f:18)
    at FirestoreSessionDAO.addSessionDoc (session.js?995f:115)
    at FirestoreSessionDAO.eval (session.js?995f:110)
    at Generator.next (<anonymous>)
    at eval (session.js?995f:22)

It seems that the firestore instance created in the FirestoreSessionDAO isn't correct or the collection() call is wrong.

To Reproduce

Init firebase and stripe

const app = !getApps().length ? initializeApp(firebaseConfig) : getApp()

const payments = getStripePayments(app, {
  productsCollection: 'products',
  customersCollection: 'customers'
})

export { app, payments }

import payments and use checkout function

import { payments } from '../services/firebase.service'
import { createCheckoutSession,  } from '@stripe/firestore-stripe-payments'

...

  methods: {
    checkout () {
      createCheckoutSession(payments, {
        price: 'price_1Jtax3GhjnzZribLiyQznali'
      }).then(session => {
        window.location.assign(session.url)
      }).catch(err => {
        console.log(err)
      })
    }
  }

...

When the method gets called there's the error in the console.

Expected behavior

Normal stripe checkout session.

System information

Windows, Chrome, [email protected], @stripe/[email protected]

Additional context

Add any other context about the problem here.

ElBouhaliMohamed avatar Nov 09 '21 18:11 ElBouhaliMohamed

Same problem: https://stackoverflow.com/questions/70013565/stripe-and-firebase-firebaseerror-expected-first-argument-to-collection-to-b?noredirect=1#comment123784766_70013565

tommtt avatar Nov 19 '21 18:11 tommtt

Same problem here, possibly related to Firebase ^9 ?

My firebase version: "firebase": "^9.1.3"

RaynoldVanHeyningen avatar Nov 19 '21 19:11 RaynoldVanHeyningen

This is likely a dependency management issue. The library is expecting a certain version of @firebase/firestore while a different one is installed with the app. Can somebody who can repro this issue please share their dependency tree with us (i.e. npm ls output)? Or even better, share a small, minimal repro that we can try locally.

hiranya911 avatar Nov 22 '21 20:11 hiranya911

├── @emotion/[email protected] ├── @emotion/[email protected] ├── @firebase/analytics 2@ extraneous ├── @firebase/app-check 2@ extraneous ├── @firebase/app-check-compat 2@ extraneous ├── @firebase/app-compat 2@ extraneous ├── @firebase/[email protected] ├── @firebase/auth-compat 2@ extraneous ├── @firebase/database 2@ extraneous ├── @firebase/database-compat 2@ extraneous ├── @firebase/firestore 2@ extraneous ├── @firebase/firestore-compat 2@ extraneous ├── @firebase/functions 2@ extraneous ├── @firebase/functions-compat 2@ extraneous ├── @firebase/installations 2@ extraneous ├── @firebase/messaging 2@ extraneous ├── @firebase/messaging-compat 2@ extraneous ├── @firebase/performance 2@ extraneous ├── @firebase/performance-compat 2@ extraneous ├── @firebase/remote-config 2@ extraneous ├── @firebase/storage 2@ extraneous ├── @firebase/storage-compat 2@ extraneous ├── @material-ui/[email protected] ├── @mui/[email protected] ├── @mui/[email protected] ├── @stripe/[email protected] ├── @testing-library/[email protected] ├── @testing-library/[email protected] ├── @testing-library/[email protected] ├── faye-websocket 2@ extraneous ├── firebase 2@ extraneous ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] └── [email protected]

tommtt avatar Nov 22 '21 20:11 tommtt

├── @chakra-ui/[email protected] ├── @emotion/[email protected] ├── @emotion/[email protected] ├── @fontsource/[email protected] ├── @stripe/[email protected] extraneous ├── @types/[email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] └── [email protected]

RaynoldVanHeyningen avatar Nov 22 '21 20:11 RaynoldVanHeyningen

Guys now it seems working! Awesome, thanks!

tommtt avatar Nov 22 '21 20:11 tommtt

Guys now it seems working! Awesome, thanks!

What did you change?

RaynoldVanHeyningen avatar Nov 22 '21 20:11 RaynoldVanHeyningen

Literally nothing. I just tried again to trigger the function and now it just works.

tommtt avatar Nov 22 '21 20:11 tommtt

I downgraded from:

"@stripe/firestore-stripe-payments": "0.0.4", to "@stripe/firestore-stripe-payments": "0.0.3",

and the bug stopped occurring.

adam-bielasty avatar Dec 12 '21 12:12 adam-bielasty

Attempted downgrading, still have the same issue.

breadcrumbbuilds avatar Dec 20 '21 21:12 breadcrumbbuilds

Still have this issue on 0.0.5 by the way

mmcenti avatar Jan 18 '22 12:01 mmcenti

What made it work for me was ensuring that Firebase-related dependencies are the same for both my app and @stripe/firestore-stripe-payments via package.json overrides.

This is how the overrides in my package.json look like for 0.0.6 of the @stripe/firestore-stripe-payments and Firebase JS SDK 9.6.6:

"overrides": { "@firebase/app": "0.7.16", "@firebase/firestore": "3.4.4" }

It's not pretty but it works for now.

alxjpzmn avatar Feb 16 '22 22:02 alxjpzmn

i have same with "overrides": { "@firebase/app": "0.7.16", "@firebase/firestore": "3.4.4" }. i'm so confused. Someone have an idea ?

drtapha avatar Mar 04 '22 13:03 drtapha

same issue here. using v.0.0.6 of stripe-payments. Tried the solutions mentioned above but that didn't work :(

jonadeline avatar Mar 28 '22 13:03 jonadeline

What made it work for me was ensuring that Firebase-related dependencies are the same for both my app and @stripe/firestore-stripe-payments via package.json overrides.

This is how the overrides in my package.json look like for 0.0.6 of the @stripe/firestore-stripe-payments and Firebase JS SDK 9.6.6:

"overrides": { "@firebase/app": "0.7.16", "@firebase/firestore": "3.4.4" }

It's not pretty but it works for now.

SEE EDIT BELOW

Previous message:

Thanks! I have used command npx howfat -r tree @stripe/firestore-stripe-payments (also I ran it with firebase package) to see exactly the version I needed, and with [email protected] and @stripe/[email protected] installed I could make it work with the following override:

"overrides": {
    "@firebase/app": "0.7.29",
    "@firebase/firestore": "3.4.13"
  }

EDIT: It broke again with the same settings, for me it's an intermittent issue and it's hard to debug.

Irian-Adappty avatar Aug 04 '22 15:08 Irian-Adappty

Any updates on this? For me using:

"overrides": {
    "@firebase/app": "0.7.29",
    "@firebase/firestore": "3.4.13"
  }

breaks the auth and is not working anyway. I'm getting FirebaseError: Firebase: Error (auth/network-request-failed). because of incompatibility (I don't have this issue when not using overrides)

Regarding Stripe payments, in my database, in /customers/:userId/checkout_sessions, I have error cannot read propery "stripeId" of null

Idk if this matters but I'm using yarn and resolutions instead of overrides

TheDomac avatar Aug 16 '22 07:08 TheDomac

Was stuck on this for days. I have a monorepo setup with PNPM workspaces.

Temporarily fixed by forcing up-to-date dependencies by adding:

"pnpm": {
  "overrides": {
    "@stripe/[email protected]>@firebase/app": "0.8.2",
    "@stripe/[email protected]>@firebase/auth": "0.20.10",
    "@stripe/[email protected]>@firebase/firestore": "3.7.1"
  }
}

to my root package.json. The particular versions where set to match the others I found commands like pnpm -F [app-name] why @firebase/app

christophemarois avatar Nov 22 '22 22:11 christophemarois

Experiencing this to. Very frustrating.

Update: so the fix is to force your package.json to use whatever version of these packages is listed in your firebase dependency (eg. by using resolutions if using yarn):

    "@firebase/app" "@firebase/auth" "@firebase/firestore"

Skwai avatar Dec 09 '22 11:12 Skwai

Experiencing this to. Very frustrating.

Update: so the fix is to force your package.json to use whatever version of these packages is listed in your firebase dependency (eg. by using resolutions if using yarn):

    "@firebase/app" "@firebase/auth" "@firebase/firestore"

Thank you for your solution Same issue here... I hope this problem will be solved

For those who don't know how to make a "resolution", here's what I did in package.json:

{
   "resolutions": {
        "@firebase/app": "0.8.2",
        "@firebase/auth": "0.20.10",
        "@firebase/firestore": "3.7.1"
    },   
}

Don't forget to run yarn install

GautierCo avatar Mar 27 '23 23:03 GautierCo

Experiencing this to. Very frustrating. Update: so the fix is to force your package.json to use whatever version of these packages is listed in your firebase dependency (eg. by using resolutions if using yarn):

    "@firebase/app" "@firebase/auth" "@firebase/firestore"

Thank you for your solution Same issue here... I hope this problem will be solved

For those who don't know how to make a "resolution", here's what I did in package.json:

{
   "resolutions": {
        "@firebase/app": "0.8.2",
        "@firebase/auth": "0.20.10",
        "@firebase/firestore": "3.7.1"
    },   
}

Don't forget to run yarn install

Thanks bro!

after so much time looking for a solution!

djkepa avatar Mar 31 '23 14:03 djkepa

This break again with "firebase": "^10.1.0" ???

RasicN avatar Aug 07 '23 04:08 RasicN

This is happening for me too using "^10.1.0" I've tried adding resolutions to the package.json file but no luck.

Any way to get around this or solve it @dackers86 ? Thank you

byroncoetsee avatar Aug 17 '23 20:08 byroncoetsee

@byroncoetsee, were you able to resolve this, please? I am also on firebase: 10.0.0

surafelbm avatar Sep 13 '23 13:09 surafelbm

This break again with "firebase": "^10.1.0" ???

@RasicN , any solutions? i am also on 10.0.0 and having the same issue

surafelbm avatar Sep 13 '23 13:09 surafelbm

Was able to find a fix for ^10.0.0 Basically, the resolutions need to match whatever the current version you are using so for this version this worked:

"resolutions": {
    "@firebase/firestore": "4.1.3",
    "@firebase/auth": "1.3.0",
    "@firebase/app": "0.9.18"
  },

I just went to node_modules/firebase/package.json and copied the versions from there, I am sure there is a yarn command you can use to find that

surafelbm avatar Sep 13 '23 13:09 surafelbm

I personally gave up on waiting and simply queried the tavbles myself, that works quite nicely but is a little extra work that we frankly expected Stripe to do...

Raketten1963 avatar Sep 13 '23 15:09 Raketten1963

@surafelbm's solution worked for me with slightly different version on npm:

  "dependencies": {
    "@invertase/firestore-stripe-payments": "^0.0.7",
    "firebase": "10.1.0",
  },
  "overrides": {
    "@firebase/app": "0.9.15",
    "@firebase/auth": "1.1.0",
    "@firebase/firestore": "4.1.0"
  }

Note: If you use npm, use override instead of yarn's resolutions

fabhed avatar Oct 26 '23 11:10 fabhed

Same problem still isn't fixed till this day. This temporary fix works as everyone above already said:

"overrides": { "@firebase/app": "0.9.25", "@firebase/auth": "1.5.1", "@firebase/firestore": "4.4.0" }

dragoscv avatar Dec 07 '23 11:12 dragoscv

I got the collection error before but using overrides to override the dependencies to the firebase package versions I get another error:

Uncaught (in promise) Error: Unexpected error while querying Firestore
    at FirestoreProductDAO.<anonymous> (@invertase_firestore-stripe-payments.js?v=c3306c19:665:15)
    at Generator.throw (<anonymous>)
    at rejected (@invertase_firestore-stripe-payments.js?v=c3306c19:493:32)

I am getting nowhere with this Firebase Extension...

SpiZeak avatar Dec 30 '23 22:12 SpiZeak

I got the collection error before but using overrides to override the dependencies to the firebase package versions I get another error:

Uncaught (in promise) Error: Unexpected error while querying Firestore
    at FirestoreProductDAO.<anonymous> (@invertase_firestore-stripe-payments.js?v=c3306c19:665:15)
    at Generator.throw (<anonymous>)
    at rejected (@invertase_firestore-stripe-payments.js?v=c3306c19:493:32)

I am getting nowhere with this Firebase Extension...

Be sure you are having the rules of db set correctly. I've managed to not have any errors anymore, everything works fine for me. Maybe share more of your code to understand your problem

dragoscv avatar Dec 30 '23 22:12 dragoscv