Firebase:如何修复错误:ENOENT:没有此类文件或目录,打开'node_modules/protobufjs/google/protobuf/api.proto'



我们正在对云火存储进行以下查询:

 ` var meeting = await db.collection("meetings").where(
    "pin", "==", request.body.Digits).where(
    "status", "==", "in-progress").get()`

这适用于我们的本地计算机,但在部署到 EC2 时会失败。我们在两者上都安装了 Firestore 客户端库,但我们在部署时对其进行了 webpack。

此错误特别令人费解,因为上面的代码片段被包装在 try 块中,但以下错误被抛出在该行上而没有被捕获:

UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'node_modules/protobufjs/google/protobuf/api.proto'
    at Object.openSync (fs.js:431:3)
    at Object.readFileSync (fs.js:333:35)
    at fetch (/home/node/server/app.compiled.js:350251:34)
    at Root.load (/home/node/server/app.compiled.js:350285:13)
    at Root.loadSync (/home/node/server/app.compiled.js:350326:17)
    at Object.loadSync (/home/node/server/app.compiled.js:347406:17)
    at Object../node_modules/@grpc/proto-loader/build/src/index.js (/home/node/server/app.compiled.js:65075:37)
    at __webpack_require__ (/home/node/server/app.compiled.js:20:30)
    at Object.<anonymous> (/home/node/server/app.compiled.js:222521:25)
    at Object../node_modules/google-gax/build/src/grpc.js (/home/node/server/app.compiled.js:222775:30)
    at __webpack_require__ (/home/node/server/app.compiled.js:20:30)
    at Object../node_modules/google-gax/build/src/index.js (/home/node/server/app.compiled.js:222819:16)
    at __webpack_require__ (/home/node/server/app.compiled.js:20:30)
    at Object.<anonymous> (/home/node/server/app.compiled.js:44631:13)
    at Object../node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js (/home/node/server/app.compiled.js:45987:30)
    at __webpack_require__ (/home/node/server/app.compiled.js:20:30)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

我们已经尝试了几乎所有你能想到的东西,而无需实际更改查询 - 重做 package.json 和我们的构建脚本,但无法弄清楚这一点。有什么帮助吗?

问题是 Node.js Cloud Firestore 的 SDK 使用 gRPC 进行通信,它是建立在原生代码之上的,有几种方法可以解决这个问题,但我建议将你的应用程序 dockerization 成这样的图像

此问题与尝试将开发工具包运行到 AWS lambda 时的问题有点相似。

希望这能为你指明一个方向

最新更新