Dan*_* Li 2 node.js firebase google-cloud-functions google-cloud-firestore
最近,我尝试在线跟踪一些演示,开始使用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();
Run Code Online (Sandbox Code Playgroud)
我开始得到这一个错误,它提到了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)
Run Code Online (Sandbox Code Playgroud)
我在互联网上环顾四周,但似乎没有其他人有这个问题.我刚刚重新安装了这些文件,但我仍然遇到了这个问题.删除Firestore和Firebase initializeApp代码可以使其正常工作,因此我认为它与此有关.
这是我的模块版本 package.json
"firebase-admin": "^5.12.0",
"firebase-functions": "^1.0.1",
"firestore": "^1.1.6",
Run Code Online (Sandbox Code Playgroud)
有没有办法解决这个问题(拙劣的安装,过时的库,缺少代码/要求等)?非常感谢你.
编辑:添加代码和package.json版本信息.我在实际文件中挖掘 \node_modules\google-gax\lib\grpc.js并发现它试图annotation.proto通过尝试google\api\annotations.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);
Run Code Online (Sandbox Code Playgroud)
遗憾的是,没有这样的目录,但可能正在寻找注释文件google-proto-files\google\api\annotations.proto(但手动添加该文件会导致进一步的错误).这里还有一个github问题https://github.com/googleapis/nodejs-firestore/issues/175提到它.
你说你正在尝试构建一个Web应用程序.但您使用的代码是在(服务器端)Node.js脚本中初始化Firebase Admin SDK.
如果要在Web应用程序中使用Firestore,请从单击此页面WEB上的选项卡时看到的代码开头:
Run Code Online (Sandbox Code Playgroud)<script src="https://www.gstatic.com/firebasejs/4.12.0/firebase.js"></script> <script src="https://www.gstatic.com/firebasejs/4.12.0/firebase-firestore.js"></script>
然后:
Run Code Online (Sandbox Code Playgroud)firebase.initializeApp({ apiKey: '### FIREBASE API KEY ###', authDomain: '### FIREBASE AUTH DOMAIN ###', projectId: '### CLOUD FIRESTORE PROJECT ID ###' }); // Initialize Cloud Firestore through Firebase var db = firebase.firestore();
您可以通过以下方式获取该initializeApp调用中的值:
| 归档时间: |
|
| 查看次数: |
276 次 |
| 最近记录: |