【发布时间】:2018-09-25 17:17:48
【问题描述】:
最近,我尝试关注一些在线演示,以开始使用 Google Firebase Cloud Functions Node.js 应用程序的服务器端代码。在尝试添加 Firebase 应用(和 Firestore)时,
const functions = require('firebase-functions');
const firebase = require('firebase-admin');
require('firebase/firestore');
var serviceAccount = require("<private key>.json");
const initAppFirebase = firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount),
databaseURL: "<URL>"
});
var db = firebase.firestore();
我开始收到一个错误,其中提到了 google-gax 模块中缺少“annotations.proto”文件(这显然是在 Firestore 中的某个时间点导入的)。
Error during trigger parsing: Error occurred while parsing your function
triggers.
Error: The include `google\api\annotations.proto` was not found.
at Function.GoogleProtoFilesRoot._findIncludePath
(C:\...\functions\node_modules\google-gax\lib\grpc.js:312:11)
at GoogleProtoFilesRoot.resolvePath
(C:\...\functions\node_modules\google-gax\lib\grpc.js:298:31)
...
at v1beta1 (C:\...\functions\node_modules\@google-
cloud\firestore\src\v1beta1\index.js:30:10)
at new Firestore (C:\...\functions\node_modules\@google-
cloud\firestore\src\index.js:229:18)
我在互联网上四处寻找,但似乎没有其他人有这个问题。我刚刚重新安装了文件,但我仍然遇到这个问题。删除 Firestore 和 Firebase initializeApp 代码允许它工作,所以我相信它与此有关。
这是我来自package.json的模块版本
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.1",
"firestore": "^1.1.6",
有没有办法解决这个问题(安装拙劣、库过时、缺少代码/要求等)?非常感谢。
编辑:为版本信息添加了代码和 package.json。我在实际文件\node_modules\google-gax\lib\grpc.js 中进行了挖掘,发现它试图通过在每个父目录中测试google\api\annotations.proto 来返回通向导入文件annotation.proto 的有效路径。
var current = originPath;
var found = fs.existsSync(path.join(current, includePath));
while (!found && current.length > 0) {
current = current.substring(0, current.lastIndexOf(path.sep));
found = fs.existsSync(path.join(current, includePath));
}
if (!found) {
throw new Error('The include `' + includePath + '` was not found.');
}
return path.join(current, includePath);
不幸的是,没有这样的目录,尽管它可能正在寻找google-proto-files\google\api\annotations.proto 中的注释文件(但手动添加该文件会导致进一步的错误)。这里还有一个github问题https://github.com/googleapis/nodejs-firestore/issues/175提到它。
【问题讨论】:
-
您能否编辑您的问题以显示出现问题的完整、最少的代码(不仅仅是几行)?
-
抱歉不清楚!我会尽快添加我的代码。
-
重要的是你没有显示
firebase的定义。
标签: node.js firebase google-cloud-firestore google-cloud-functions