无法获取文档的FireStore
运行准系统节点文件时加载“protobuf.js”:无法获取文档的FireStore
const firebase = require("firebase");
const http = require('http')
require("firebase/firestore");
firebase.initializeApp({
apiKey: '...',
authDomain: '...',
databaseURL: '...',
serviceAccount: '...',
projectId: '...'
});
var db = firebase.firestore();
var userRef = db.collection('...').doc('...');
结果在下面的终端规则
Firestore (4.5.2) 2017-10-18T19:16:47.719Z: INTERNAL UNHANDLED ERROR: Error: Failed to fetch file at /.../project/node_modules/protobufjs/dist/protobuf.js:5164:30 at ReadFileContext.callback (/.../p/node_modules/protobufjs/dist/protobuf.js:358:29) at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:420:13) (node:43981) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to fetch file (node:43981) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
但我查了node_modules文件夹,它的存在。我也尝试重新安装它,其他人似乎没有与当前版本的protobuf.js有问题。
类似的问题:
const firebase = require('firebase');
require("firebase/firestore");
const config = {
apiKey: "-redacted-",
authDomain: "-redacted-",
databaseURL: "-redacted-",
projectId: "-redacted-",
storageBucket: "-redacted-",
messagingSenderId: "-redacted-"
};
firebase.initializeApp(config);
let db = firebase.firestore();
let ref=db.collection('example').doc('test');
ref.set({test:true});
错误控制台(节点v6.11.4):
Firestore (4.5.2) 2017-10-18T19:48:00.297Z: INTERNAL UNHANDLED ERROR: Error: Failed to fetch file
at Error (native)
at /Users/krispy.uccello/Development/devrel/constellation/functions/node_modules/protobufjs/dist/protobuf.js:5164:30
at ReadFileContext.callback (/Users/krispy.uccello/Development/devrel/constellation/functions/node_modules/protobufjs/dist/protobuf.js:358:29)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:367:13)
(节点:71564)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:1):错误:无法抓取文件
的数据库规则:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
更新: 此问题似乎只与写入有关。我能够毫无问题地从Firestore读取数据。
更新#2: 我写了一个firebase函数来处理写操作,它的工作。这个问题可能与客户端安装的protobuf js的发布版本有关。不确定在Firebase端使用了哪些版本,但似乎可行。查看通过firebase https触发器调用的以下函数 - 它的工作原理和数据显示在firestore数据库中。
function writeWorkerProfile(id, data, res) {
let ref =
db.collection('scratch').doc('v1').collection('workers').doc(`${id}`);
ref.set(data)
.then(function() {
console.log("Document successfully written!");
res.status(200).send({ok:true})
})
.catch(function(error) {
console.error("Error writing document: ", error);
res.status(500).send('Error occurred: Could not write data');
});
}
你用什么代码阅读?您是如何启动Firebase https触发器的?谢谢! (对此为新的) – user61871
请参阅以下要点 https://gist.github.com/kuccello/d68f671ad396b8741bcdd47a7218044b https://gist.github.com/kuccello/4d367cc011aa941a456f60a01826a02f – Krispy
以下是读取功能: https:// gist .github.com/kuccello/0ae3314bdf4d14128ee41e05cb4b5507 – Krispy
我今天有同样的问题。添加下面的答案以显示类似的方法并记录输出和配置。 – Krispy