dimanche 31 mai 2020

Why is `TypeError: firebase.initializeApp is not a function` occurring only when @firebase/testing is imported in a submodule to a cypress plugin?

I am using Cypress to test an app and using Cypress Tasks to run backend database seeding.

The backend is a locally emulated Firestore database.

Usually, I am able to run initializeAdminApp() without problems, from my Cypress plugins file. I am using the new built-in TS capabilities of Cypress.

When I import @firebase/testing in my plugins/index.ts file, there is no issue at all.

But if I instead import @myapp/testing which imports @firebase/testing and runs initializeAdminApp(), I get TypeError: firebase.initializeApp is not a function.

So I was able to fix the issue by simply adding this to my plugins/index.ts file:

import * as testing from '@firebase/testing';
testing;

And then the rest of the code (that was crashing before with that error) suddenly works fine.

I've even console logged the testing object from my submodule. It shows all the property keys as per normal.

Simply importing it and referencing the imported variable in a pointless expression, makes the function not crash when imported and used in a submodule.

Using an NX monorepo. Any ideas appreciated!

Aucun commentaire:

Enregistrer un commentaire