Google cloud firestore 对Firestore的调用在本地通过Shell工作,但在部署到云函数后给出空错误

Google cloud firestore 对Firestore的调用在本地通过Shell工作,但在部署到云函数后给出空错误,google-cloud-firestore,google-cloud-functions,google-admin-sdk,firebase-cli,firebase-tools,Google Cloud Firestore,Google Cloud Functions,Google Admin Sdk,Firebase Cli,Firebase Tools,我正在使用Firebase函数对Firestore进行查询。当我从本地shell运行函数时,一切正常 但是,在部署代码并调用函数后,Firestore在生产中返回一个空白错误{} Firestore权限不应该是这里的问题,因为它在本地工作 服务帐户也不应成为问题 没有错误消息或调试信息。我还检查了服务器控制台上的功能日志 firestore.collection("users").doc(uid).set(userJson, {merge:true}) .then((

我正在使用Firebase函数对Firestore进行查询。当我从本地shell运行函数时,一切正常

但是,在部署代码并调用函数后,Firestore在生产中返回一个空白错误{}

Firestore权限不应该是这里的问题,因为它在本地工作

服务帐户也不应成为问题

没有错误消息或调试信息。我还检查了服务器控制台上的功能日志

firestore.collection("users").doc(uid).set(userJson, {merge:true})
    .then((done) => {
        console.log('Created new user');
    }).catch(err => {
        console.log('Error creating new user:', JSON.stringify(err));
    });
Package.json

"engines": { "node": "8" }
我希望部署后的行为与shell中的行为相同。如何从Firebase Functions server获取对Firestore work的调用

  • 检查/functions文件夹(由firebase init创建)中的package.json文件。确保您使用的是受支持的最新版本的NodeJS。截至2020年,应为NodeJS 10:

    “引擎”:{“节点”:“10”}

  • 确保您使用的是最新版本的Firebase CLI。到2020年,它应该是8.10.0

    npm安装-g firebase工具

  • 如果不起作用,请先清理缓存
    npm cache clean--force
    ,然后重试

  • 确保传递到firestore查询的负载没有空白键未定义值
  • Firestore调用是异步的(它们返回一个承诺)。在Firestore调用完成之前,确保没有返回响应
    response.send()
    。正确使用
    async/await
    .then()
  • 注意:您可能不需要显式配置管理员SDK服务帐户,因为默认服务帐户已经具有从云功能访问Firestore的权限

    npm list -g --depth=0 
    npm uninstall -g firebase-tools
    npm install -g firebase-tools
    npm list -g --depth=0
    
    firestore.collection("users").doc("123").set({
        id: 1234,
        '': 'something', // ERROR
        phone: undefined, // ERROR
        email: 'user@email.com'
    })