Skip to content

Firestore fails to load protobuf file #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Nov 8, 2017 · 14 comments
Closed

Firestore fails to load protobuf file #303

ghost opened this issue Nov 8, 2017 · 14 comments

Comments

@ghost
Copy link

ghost commented Nov 8, 2017

Describe your environment

  • Operating System version: OSX 10.12.6
  • Firebase SDK version: 4.6.1
  • Firebase Product: firestore
  • Platform: Node v8.9.0

Describe the problem

protobufjs.loadProtoFile for 'google/firestore/v1beta1/firestore.proto' always fails due to this file missing in the published versions (tested with 4.6.0 and 4.6.1).

Steps to reproduce:

I'm able to reproduce consistently with this code in a fresh repo after running yarn add firebase:

const firebase = require('firebase');
require('firebase/firestore');

const customToken = '...';
firebase.initializeApp({
  apiKey: '...',
  projectId: '...',
});

firebase.auth().signInWithCustomToken(customToken);

db.collection('test').doc('1234').get().then((doc) => {
  console.log('doc', doc);
});

This causes the following:

Firestore (4.6.1) 2017-11-08T01:51:23.677Z: INTERNAL UNHANDLED ERROR:  Error: Failed to fetch file
    at /Users/justin/test/node_modules/protobufjs/dist/protobuf.js:5164:30
    at ReadFileContext.callback (/Users/justin/test/node_modules/protobufjs/dist/protobuf.js:358:29)
    at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:420:13)
(node:81214) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to fetch file

Attempts to make requests after this fail with:

Error: FIRESTORE (4.6.1) INTERNAL ASSERTION FAILED: AsyncQueue is already failed: Failed to fetch file
    at Object.fail (/Users/justin/test/node_modules/@firebase/firestore/dist/cjs/src/util/assert.js:35:11)
    at AsyncQueue.schedule (/Users/justin/test/node_modules/@firebase/firestore/dist/cjs/src/util/async_queue.js:41:22)
    at FirestoreClient.listen (/Users/justin/test/node_modules/@firebase/firestore/dist/cjs/src/core/firestore_client.js:267:25)
    at DocumentReference.onSnapshotInternal (/Users/justin/test/node_modules/@firebase/firestore/dist/cjs/src/api/database.js:564:54)
    at /Users/justin/test/node_modules/@firebase/firestore/dist/cjs/src/api/database.js:574:34
    at new Promise (<anonymous>)
    at DocumentReference.get (/Users/justin/test/node_modules/@firebase/firestore/dist/cjs/src/api/database.js:573:16)
    at repl:1:16
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:240:29)

Specifically it looks like https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/platform_node/load_protos.ts#L46-L50 is trying to load a file that would be in /Users/justin/test/node_modules/@firebase/firestore/dist/cjs/src/protos for example but this directory doesn't exist, though it does here: https://github.com/firebase/firebase-js-sdk/tree/master/packages/firestore/src. The only protos directory I can find is here:

~/test$ find . -name protos
./node_modules/@google-cloud/firestore/protos
@google-oss-bot
Copy link
Contributor

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@hiepxanh
Copy link

hiepxanh commented Nov 8, 2017

I have the same isssue when I tries to use take(1) query for my Serverside Rendering App (angular universal), I try to reinstall but it still the same problem. Don't know what to do

@dzjin
Copy link

dzjin commented Nov 14, 2017

I ran into this problem because:

  • I was using Firestore, and its dependency may have changed
  • I used "web" version in trying to fix the issue above, when my project was server-side

I fixed it after finding it in Node docs on https://cloud.google.com/firestore/docs/quickstart

/** deprecated **/

const Firestore = require('@google-cloud/firestore');
const config = {
  apiKey: 
  authDomain: 
  projectId: 
};
const t = new Firestore(config);
export default t;

/** browser, not server **/

const firebase = require("firebase");
require("firebase/firestore");
firebase.initializeApp({
  apiKey: '### FIREBASE API KEY ###',
  authDomain: '### FIREBASE AUTH DOMAIN ###',
  projectId: '### CLOUD FIRESTORE PROJECT ID ###'
});
var db = firebase.firestore();
export db;


/** working **/

const admin = require('firebase-admin');
const serviceAccount = require("/my-service-credentials.json");
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});
const db = admin.firestore();
export default db;

@ghost
Copy link
Author

ghost commented Nov 14, 2017

@dzjin the problem is specifically with the firebase-js-sdk library, the firebase-admin library indeed works correctly.

I used the former because I wanted to test out client behavior around authenticating with custom tokens and then making queries on data to test permission rules. I had to run the test in a browser instead of in a node console due to this issue.

@hiepxanh
Copy link

I have a question: if I'm using firestore on angular but it is SSR (universal), I'm using firestore for client or server ?
I'm using firestore for client but I'm rendering it on server, what is this call ?

@dzjin
Copy link

dzjin commented Nov 15, 2017

@hiepxanh that'd depend on where the code will run, so I think you'll need to import two different projects for firebase:

use firebase-js-sdk for client code (second example #303 (comment)) and use firebase-admin for server-side code (third example).

@hiepxanh
Copy link

hiepxanh commented Nov 15, 2017

oh my god, how can I put firebase-admin in my angular component without angularfire2, that really a bad news. :(

this is really a serious problem if you have a production app

@mikamaunula
Copy link

Same problem with my code also. In my case nodejs service needs to be client.

@jshcrowthe
Copy link
Contributor

jshcrowthe commented Nov 16, 2017

Hey guys thanks so much for your interest in firestore! I'm going to close this in favor of #221 as this is a known issue. Additionally you can feel free to go thumbs up #319 which is the fix!

@hiepxanh
Copy link

thanks god, good to know you are fixing this I love this @jshcrowthe

@alexandregiordanelli
Copy link

same problem here using Firebase SDK version: 4.6.2 and firestore 4.6.1
(running server side)
import firebase from 'firebase/app'
import 'firebase/firestore'

@hiepxanh
Copy link

look like he still does not finish that fix

@alexandregiordanelli
Copy link

Firestore (4.6.1) 2017-11-26T14:28:26.397Z: INTERNAL UNHANDLED ERROR: Error: Failed to fetch file

node_modules/protobufjs/dist/protobuf.js:5164:30

@tonypee
Copy link

tonypee commented Dec 6, 2017

Im still experiencing this, with some queries (others work)

"firebase": "^4.7.0",

I am doing a WHERE

db.collection('orders')
.where('token', '==', token)
.get()

@firebase firebase locked and limited conversation to collaborators Oct 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants