简体   繁体   English

firebase/firestore/lite 不适用于 firebase 模拟器?

[英]firebase/firestore/lite doesn't work with firebase emulator?

I'm using Firebase SDK JS 9.15.0 with Node.js 18.12.1.我正在使用 Firebase SDK JS 9.15.0 和 Node.js 18.12.1。 I'm using firebase emulator to test some Firestore operations.我正在使用 firebase 模拟器来测试一些 Firestore 操作。 If I use functions/modules from firebase/firestore everything works fine.如果我使用firebase/firestore中的函数/模块,一切正常。 While if I use the same functions/modules firebase/firestore/lite I got en error.如果我使用相同的功能/模块firebase/firestore/lite ,我会遇到错误。 Only when connectFirestoreEmulator is called: both modules work fine connecting directy with real Firestore.仅当调用connectFirestoreEmulator时:两个模块都可以正常连接到真正的 Firestore。

Here is the code to test.这是要测试的代码。 The working one:工作的一个:

import { initializeApp } from 'firebase/app';
import { getFirestore, collection, doc, setDoc, getDoc, connectFirestoreEmulator} from 'firebase/firestore';

const firebaseConfig = {
// ... Configuration here
  };

const app = initializeApp(firebaseConfig);

const firestoreDB = getFirestore(app);
connectFirestoreEmulator(firestoreDB, 'localhost', 8080);

const collectionRef = collection(firestoreDB, 'CollectionName');
const docRef = doc(collectionRef, "DocID");
setDoc(docRef, {
    name: "DocumentName"
  }).then(() => 
  {
        console.log("OK");
  });

On the other side, this return an error:另一方面,这会返回一个错误:

import { initializeApp } from 'firebase/app';
import { getFirestore, collection, doc, setDoc, getDoc, connectFirestoreEmulator} from 'firebase/firestore/lite';

const firebaseConfig = {
// ... Configuration here
  };

const app = initializeApp(firebaseConfig);

const firestoreDB = getFirestore(app);
connectFirestoreEmulator(firestoreDB, 'localhost', 8080);

const collectionRef = collection(firestoreDB, 'CollectionName');
const docRef = doc(collectionRef, "DocID");
setDoc(docRef, {
    name: "FieldName"
  }).then(() => 
  {
        console.log("OK");
  });

and the error is错误是

[2023-01-13T11:42:51.832Z]  @firebase/firestore: Firestore (9.15.0_lite): RPC_ERROR HTTP error has no status
[2023-01-13T11:42:51.835Z]  @firebase/firestore: Firestore (9.15.0_lite): RestConnection Commit failed with error:  [FirebaseError: Request failed with error: undefined] {
  code: 'unknown',
  customData: undefined,
  toString: [Function (anonymous)]
} url:  http://localhost:8080/v1/projects/<my-project-name>/databases/(default)/documents:commit request: {
  writes: [
    {
      update: {
        name: 'projects/<my-project-name>/databases/(default)/documents/CollectionName/DocID',
        fields: { name: { stringValue: 'FieldName' } }
      }
    }
  ]
}
Waiting for the debugger to disconnect...
node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[FirebaseError: Request failed with error: undefined] {
  code: 'unknown',
  customData: undefined,
  toString: [Function (anonymous)]
}

Does anyone have an idea if I can use firebase emulator with firestore lite?有谁知道我是否可以将 firebase 模拟器与 firestore lite 一起使用? thanks谢谢

Do you have firebase-firestore-lite installed?你有安装 firebase-firestore-lite 吗?

npm install firebase-firestore-lite npm 安装 firebase-firestore-lite

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM