Running a barebones node file:
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('...');
Results in the following terminal rule
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.
But I checked the node_modules folder and it's there. I also tried reinstalling it, and other people dont seem to have had problems with the current version of protobuf.js.
Similar Issue:
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});
Error in console (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)
(node:71564) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to fetch file
Database Rules:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
Update: This issue seems to be related to writes only. I was able to read data from Firestore without issue.
Update #2: I wrote a firebase function to handle the write operation and it worked. The issue could be related the published version of protobuf js that is being installed on the client side. Not sure what version is being used on the Firebase end but it appears to work. See the following function that is invoked through a firebase https trigger - it works and data appears in the firestore database.
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');
});
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments