-
Notifications
You must be signed in to change notification settings - Fork 938
SSR / Firestore / Not able to load proto file #3541
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
Comments
@vroussel35 Thanks for filing this. Can you try the steps outlined here: https://stackoverflow.com/questions/61182267/nestjs-angular-universal-not-working-error-enabling-offline-persistence ? Otherwise, it is possible to specify a custom proto directory via the environment variable |
Hi @schmidt-sebastian - thanks for your reply. SO link FIRESTORE_PROTO_ROOT |
The problem is that firestore is bundled while it should not be in the Node environment. Firestore has a special Nodejs build and assumes it runs in As a workaround, you should exclude any firebase package including firestore from being bundled when doing SSR. Can you try the solution I provided for a similar issue? Does it solve your problem? |
The problem if we add firestore packages to the externalDependencies server build block in our angular.json like this:
We have now a new error :
|
Progressing on our investigations... We found a way to fix our last issue In the module/class/service calling the
Now, we are facing another issue : our query to Firestore is hanging and never return to the client. I think it's something related to the Angular Zone topic. If someone has any information related to this, let me know. Regarding this specific issue: I suspect we are not the only ones facing this issue so what can be done to fix it without the need of these workarounds? I guess the firebase package could identify if it's running on Node and then do the mentioned workarounds above? |
Calling |
@schmidt-sebastian What is the purpose of this function? Can you explain why we shouldn't need to do that? From what we have seen, @angular/fire (and @jamesdaniels) seems to call it when in a node context.
We tried it and it's kind of working on SSR - our problem is this package is based on Observables and our need is to perform several Promises - so that's why we would like to use the default If we are using the @angular/fire package, we could have used the For example: This works => query is done and SSR is rendered.
This doesn't work: calling
|
Hey @vroussel35, seems like you are finding all the sharp edges with Firebase + Angular that we've been working on over on AngularFire. The root of your rendering issue is that Firebase isn't Zone.js patched. It's side-effects (Timers, sockets, etc.) destabilize Zone.js and keep SSR from rendering and your service workers from initializing in the browser. As you've noted we've solved this in AngularFire but are Observable based. TBH this.angularFirestore.collection(
'collectionId', ref => ref.where('field', '==', 'value'))
).get() You could always make a promise out of the subscription yourself: new Promise((resolve, reject) =>
this.angularFirestore.collection(
'collectionId', ref => ref.where('field', '==', 'value'))
.snapshotChanges().pipe((take(1)).subscribe(values => {
resolve(values)
})
); |
registerFirestore() is an internal function that we use to inject Firestore into firebase's namespace. We offer no guarantee about its functionality or its name, and it is even mangled in some of our builds. Only APIs exposed via our Typescript definition files (and hence mentioned in our docs) are guaranteed to be stable. |
@schmidt-sebastian I can definitely confirm that you need to call |
@jamesdaniels @Feiyang1 We probably need to find a solution for this as |
FWIW I imagine the root cause is over aggressive tree-shaking somewhere in the |
@vroussel35 Can you add all firebase packages to If you only exclude The unbundled |
@jamesdaniels the get() function returns an Observable ;). I tested it and it seems the get function is not appropriately Zone wrapped: the page with a simple get call renders always exactly after 60 seconds.
@Feiyang1 I can confirm adding all firebase packages to Here is my angular.json "server" config:
@jamesdaniels @Feiyang1 @schmidt-sebastian I will close this issue as this specific issue is resolved by adding all the @firebase packages to the externalDependancies. But I will create another issue (with repo and steps to reproduce) to tackle the other issue with - for example - a very basic firestore get() call like shown below which is never SSR'ed / rendered:
|
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
In an Angular Universal (SSR) context, calling firestore method on the server does not work.
Error enabling offline persistence. Falling back to persistence disabled: Error: ENOENT: no such file or directory, open '[project-directory-path]/dist/server/src/protos/google/firestore/v1/firestore.proto'
Problem identified in the function loadProtos() : node_modules/@firebase/firestore/dist/index.node.cjs.js (line 22969)
The value of
__dirname
is the project directory path and therefore, during execution,node_modules/@firebase/firestore/dist/src/protos
path can't be foundSteps to reproduce:
Download this repository https://github.com/vroussel35/error-proto then
npm install
npm run dev:ssr
Browse http://localhost:4200/
// TODO(you): code here to reproduce the problem
The text was updated successfully, but these errors were encountered: