samedi 26 septembre 2020

Cannot find module 'firebase-admin' from 'index.cjs.js'

I was using @firebase/testing on Jest, but since it's deprecated and instructed to use new one, I decided to move to @firebase/rules-unit-testing.

Here is the code where I just switched them.

import { initializeAdminApp } from "@firebase/rules-unit-testing";
import "babel-polyfill";

it("is ok", async () => {
  const admin = initializeAdminApp({ projectId: "my-project" });

  try {
    const doc = admin.firestore().collection("items").doc("item-1");
    await doc.set({ name: "Item 1" });
    const ss = await doc.get();
    expect(ss.data()?.name).toBe("Item 1");
  } finally {
    await admin.delete();
  }
});

When I run this test with emu, it results "Cannot find module 'firebase-admin' from 'index.cjs.js'" error.

Cannot find module 'firebase-admin' from 'index.cjs.js'                      
                                                                                              
      3 |                                       
      4 | it("is ok", async () => {                                                              
    > 5 |   const admin = initializeAdminApp({ projectId: "my-project" });                           
        |                 ^

It passes if it is the old @firebase/testing.

What did I miss?

  • Node.js v14.8.0
  • Jest 25.5.4
  • firebase 7.21.1
  • firebase-tools 8.11.2
  • @firebase/testing 0.20.11
  • @firebase/rules-unit-testing 1.0.4

Aucun commentaire:

Enregistrer un commentaire