运行一个简单的节点文件:
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('...');结果如下终端规则:
修复(4.5.2) 2017-10-18T19:16:47.719Z:内部未处理错误:错误:在/.../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 (节点:43981)获取文件失败UnhandledPromiseRejectionWarning:未处理承诺拒绝(拒绝id: 1):错误:失败要获取文件(节点:43981),不推荐DEP0018 DeprecationWarning:未处理的承诺拒绝。在未来,承诺不处理的拒绝将使用非零退出代码终止Node.js进程。
但是我检查了node_modules文件夹,它就在那里。我也尝试过重新安装它,其他人似乎对当前版本的protobuf.js没有任何问题。
发布于 2017-10-18 19:53:20
类似问题:
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});控制台中的错误(Node 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的发布版本有关。不确定在Firebase端使用的是哪个版本,但它似乎有效。请参见通过firebase触发器调用的以下函数--它可以工作,数据显示在消防站数据库中。
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');
});
}https://stackoverflow.com/questions/46817763
复制相似问题