Unable to load 'protobuf.js' when fetching Firestore document

user61871

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.

Krispy

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.

edited at
0

Comments

0 comments
Login to comment

Related

Fetching a firestore document from node.js errors

Obtaining DocumentReference of Firestore document without fetching document

Loading when fetching firestore data

Firestore recycler adapter not fetching document names

Kotlin Firestore - Fetching Fields from Specific Document

Get document id from Firestore after fetching document

Load Firestore document first in Flutter

Unable to read the value of a document - Firestore

Unable to update document in cloud firestore

prepare for segue when fetching data from firestore

forEach link not appearing as clickable when fetching for Firestore

How to show Circular progress indicator while fetching document from Firestore

Run JS function on document load and when a certain element is clicked [Tampermonkey]

Save document ID when creating a document in Firestore

Besides black magic, what could cause inclusion of js/css files in their containing html document when fetching a page over http vs https?

Cloud Firestore unable to retrieve document or field

Unable to retrieve document from Firestore with Flutter

forEach link not appearing as clickable when fetching from Firestore

Issue when fetching random documents from Firebase Firestore with Swift on iOS

Is there any reason not to call data() immediately when fetching data from firestore?

Slight delay/lag when fetching Firestore User data to update View

Unable to load pdf from document directory in Swift

How to throw a server error when fetching JS

Setting a firestore document when a new user is created with firebase auth using node.js

Load more only works once when fetching from api in react

Fetching data on page load and assigning it to select optins in Vue JS

Unable to catch error when fetching data in async function

unable to update hooks variable when fetching multiple urls in react

Fetching Document-id using where clause (Firebase Firestore with Android Studio)