Firebase 函数 ENOENT:没有这样的文件或目录,打开 'HttpsErrorImpl'

Firebase Functions ENOENT: no such file or directory, open 'HttpsErrorImpl'

我已经为这个问题奋斗了 3 天多了。我不知道发生了什么。

Firebase Functions 仅在我尝试使用 Emulator 时抛出错误。我尝试在 useEffect 挂钩中执行此功能。同样,当我调用已部署的 Cloud Functions 时,一切似乎都很好,不幸的是,如果使用 Emulator,事情就不会那么顺利了。

const resolvePromise = async () => {
      functions.useEmulator("https://0.0.0.0:5001");
      const query = functions.httpsCallable("helloWorld");
      query()
        .then((result) => console.log(result))
        .catch((err) => console.log(err));
    };

我收到这个(对我来说)无用的错误。

Error: ENOENT: no such file or directory, open 'HttpsErrorImpl@http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false'
    at Object.openSync (node:fs:585:3)
    at Object.readFileSync (node:fs:453:35)
    at getCodeFrame (Z:\repo\PTCG_Marketplace\node_modules\metro\src\Server.js:1296:18)  
    at Z:\repo\PTCG_Marketplace\node_modules\metro\src\Server.js:1367:24
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (Z:\repo\PTCG_Marketplace\node_modules\metro\src\Server.js:146:24)
    at _next (Z:\repo\PTCG_Marketplace\node_modules\metro\src\Server.js:168:9)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

internal
at HttpsErrorImpl@http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:197178:29 in <unknown>
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:197273:29 in _errorForResponse
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:197751:39 in <unknown>
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:170357:26 in step
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:170287:21 in <unknown>
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:170241:31 in fulfilled
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:31526:15 in tryCallOne
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:31627:26 in <unknown>
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:31955:16 in _callTimer
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:31994:16 in _callImmediatesPass
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:32211:32 in callImmediates
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:3457:34 in __callImmediates
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:3236:33 in <unknown>
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:3440:14 in __guard
at http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false:3235:20 in flushedQueue

这是我访问后看到的全部文字

http://192.168.0.104:19000/index.bundle -- https://pastebin.com/ggsCMN0W http://192.168.0.104:19000/index.bundle?platform=android&dev=true&hot=false&minify=false -- https://pastebin.com/LSeufs8H

这对我来说没有任何意义。在第二个地址,它似乎与地铁依赖相关,所以我更新了它,它没有用。

有什么想法吗?提前致谢 :D

编辑 1:所有错误都记录在客户端站点,似乎客户端甚至无法调用模拟器。

编辑 2: 我尝试将整个 firebase 更新为 v.9 以及将 Expo 更新为 44 SKD 并将 react-native 更新为 0.64.3

这是我的请求函数现在的样子:

  const requestApi = () => {
    const functions = getFunctions(app);
    connectFunctionsEmulator(functions, "127.0.0.1", 5001);
    const helloWorld = httpsCallable(functions, "helloWorld");
    helloWorld()
      .then((result) => {
        console.log(result);
      })
      .catch((error) => {
        console.log(error.message, error.code, error.details);
      });
  };

我只从 catch 块收到这个:(

internal functions/internal undefined

我在执行该函数后也收到有关计时器的警告

Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info. (Saw setTimeout with duration 70000ms)

只有当我尝试使用 Emulator 时它不工作

这里有几个潜在问题:

  1. 假设您使用的是最新版本的 Firebase,函数实际上是一种方法:firebase.functions().useEmulator("localhost", 5001); - 请注意 functions 之后的 ()See docs 获取更多信息。
  2. 也许您已经这样做了,但是您是否确定功能模拟器实际上是 运行 并且可以连接到端口 5001)?通过 Postman 或类似工具对其进行测试可能很有用。
  3. 确保您使用正确的 IP 地址用于给定您的设置的函数模拟器。 0.0.0.0 可能不会映射到您想要的位置...假设应用程序在本地 运行 并且功能模拟器也是,请尝试 127.0.0.1 或“localhost” ... 有更多选项可以解决问题。

我不确定是不是你的情况,但我有一个功能:

exports.findUserInAuth = functions.https.onCall((data, context) => {
  let field = data.field;
  let value = data.value;

  if (!field || !value) {
    return false;
  }

  if (field === "email") {
    return admin.auth().getUserByEmail(value);
  }
});

这个 return 是一个承诺,我不得不更改它以等待结果,然后再做 return 问题解决了...

exports.findUserInAuth = functions.https.onCall((data, context) => {
  let field = data.field;
  let value = data.value;

  if (!field || !value) {
    return false;
  }

  if (field === "email") {
    admin.auth().getUserByEmail(value).then((result) => {
        return result;
      })
      .catch((error) => {
        if (error.code === "auth/user-not-found") {
          return "Email or Password is incorrect";
        }

        return `${error.code} ${error.message}`;
      });
  }

  return false;
});

好的,所以在与这个狗屎战斗了将近一周之后!

当你像我一样使用 Expo Go 时。您应该复制您在其上模拟您的应用程序的主机地址,并使用您模拟您的功能(或其他工具)的相同地址。

app.json

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "emulators": {
    "functions": {
      "host": "192.168.0.104",
      "port": 5001
    }
  }
}

requestApi函数的最终代码

const requestApi = async () => {
    const functions = firebase.functions()

    functions.useEmulator("192.168.0.104", 5001);   <--- ADDRESS!!!

    const helloWorld = functions.httpsCallable("helloWorld");
    helloWorld()
      .then((result) => {
        console.log(result);
      })
      .catch((error) => {
        console.log(error.message, error.code, error.details);
      });
  };