Solvedangularfire Angular Ivy 9.0 stable and angularfire RC1 using Firestore have trouble with Universal

Version info

Angular:
"@angular/animations": "~9.0.0", "@angular/cdk": "^9.0.0", "@angular/common": "~9.0.0", "@angular/compiler": "~9.0.0", "@angular/core": "~9.0.0",
Firebase:

"_from": "firebase@>= 5.5.7 <8",
  "_id": "firebase@7.8.1",

AngularFire:

"@angular/fire": "^6.0.0-rc.1",

How to reproduce these conditions

stackbliz
github

project link will be delete after resolve this issue

Steps to set up and reproduce

after adding Angularfire, it's work normally. But when I start with Universal build, it have problem, clone project and start:
npm run dev:ssr

Debug output

E:\coronavirus-tracking\dist\coronavirus-tracking\ser
ver\main.js:197014
        throw new Error("package.json does not exist at " + package_json_path);
        ^

Error: package.json does not exist at E:\coronavirus-tracking\dist\coronavirus-tracking\package.json
    at Object../node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js.exports.find (E:\coronavirus-tracking\dist\coronavirus-tracking\server\main.js:197014:15)

** Screenshots **
image

after comment firebase library:
image

look like the error disappear but sure. angularfire cannot run without firebase/firestore

Expected behavior

not have error when building with universal

Actual behavior

build not succesful

already read about:
#2284
angular issue #34544
#2280

i'm starting desperated after 5 hours

Updated

universal #1207 suggest adding this but it not work:

// angular.json >  architect.server.options
"externalDependencies": [
  "grpc",
  "@grpc/proto-loader"
]

image

Updated 1

#2284 suggest adding "@angular/fire/firestore" seem work but got other error:

// angular.json >  architect.server.options
"externalDependencies": [
  "grpc",
  "@grpc/proto-loader",
   @angular/fire/firestore"
]

image
image

Cannot read property 'id' of undefined

Reference to this update 2

update 3:

add "bundleDependencies": true to angular.json then run npm run build:ssr && npm run serve:ssr having this issues. guest that relate to this #2280

ERROR Error: inject() must be called from an injection context

image

solution: https://github.com/hiepxanh/angularfire2/blob/a45e0ad4f1c918e78a1610d2b73dee3cc9b1f6b1/docs/universal/getting-started.md

55 Answers

✔️Accepted Answer

I am aiming to achieve success bundling us with Angular 9 SSR within a week. Depending on the day of the week I get it merged, other issues in the meantime, or how big that particular change is I may decide to cut another RC before 6.0 drops on @latest.

Other Answers:

After much suffering I've managed to get this working!

I have a couple more things to clean up and will be cutting a new RC shortly. I had to add @firebase/firestore to externalDependencies and make some other baffling changes... honestly I'm not 100% sure how this is working but I'm going to roll with it.

It's very clear that NGCC does not like how Firestore is bundled. I'll grab some time with the JS SDK team when opportune.

I understand sir @tiagorvs, but I would like to work with ivy to get the best performance since angular 9 enable ivy by default

any update on a working ssr with the latest version and angular 9 ivy?

@fayeyen they close my issues, so I close my PR #2372
little dissappoint but here is the solution:

SOLUTION:

Description
update for angular 9.0 match with https://angular.io/guide/universal

Code sample
example repository here https://github.com/hiepxanh/angular-fire-universal

SNIPPET:

1. Edit file

Insert polyfills at the top of file

// server.ts
...
// Polyfills required for Firebase
(global as any).WebSocket = require('ws');
(global as any).XMLHttpRequest = require('xhr2');
...
// angular.json
// projects.web.architect
...
 "server": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            ...
            "externalDependencies": [
              "@firebase/firestore"
            ]
            ...
          }


...

2. Setup Firebase detail

3. Running

npm run dev:ssr

Related Issues:

251
angularfire Missing exported members after updating to Angular 6.0.0
It looks like rxjs-compat is missing Use npm i rxjs-compat to install the missing rxjs-compat. ...
184
angularfire ERROR TypeError: Object(…) is not a function” using AngularFirestore and firebase
@jamesdaniels Yes npm install rxjs@6 rxjs-compat@6 --save It solved the issue. I want to use firebas...
164
angularfire @firebase/firestore: Firestore (5.8.0): timestampsInSnapshots
eg: app.module.ts Version info Angular: 7.2.1 Firebase: 5.8.0 AngularFire: 5.1.1 In the newest fireb...
142
angularfire 5.2.1 AngularFireAuthGuard causes TypeError: source.lift is not a function
I worked in this way Performing basic docs for AngularFireAuthGuard produces an error related to sou...
60
angularfire Just get the value once with no subscription
Use .take(1) which will kill the subscription once the first value has emitted. ...
46
angularfire [ERROR] Class 'FirebaseApp' incorrectly implements interface 'App'
Just to be super clear $ ionic cordova run browser Running app-scripts build: --platform browser --t...
46
angularfire Build error: This module is declared with using 'export ='
I see.. What happens when you add these entries to compilerOptions in tsconfig? ...
44
angularfire How to order by date?
Hey guys I just implemented a solution also to this using the mapping function this will return an O...
39
angularfire Namespace 'firebase' has no exported member 'Promise'.
Hey @dauledk! firebase.Promise was removed in version 4.5.0 of the firebase SDK Now you just use a r...
33
angularfire CollectionReference.doc function path should be optional
I agree this should align with the Firebase SDK A potential workaround is to use a pattern like this...
29
angularfire Cannot find namespace 'firebase'.
I am using angularfire2 in an ionic 2 project and I was getting the same error With the new angularf...
25
angularfire Firebase Storage is not working with ionic 3 & AngularFire 4.0.0 rc
Hey guys I was having this same problem but getting an issue where it was saying that my Firebase ap...
25
angularfire Calling AngularFireFunctions.httpsCallable results to error 404 because
The issue seems to come from #1920 (this file) resolving #1874 To get around it for now you can do t...
23
angularfire auth.login() Error "location.protocol" must be http or https
does it make sense to add some Help Wanted! or other label to raise the importance/severity? looks l...
22
angularfire Ducumentation Issues
@Anystrous Update: I see the problem The docs need this fix: We had breaking changes in version 5.0 ...
21
angularfire Cannot read property 'FacebookAuthProvider' of undefined - 2.0.0-beta.5
@arielcessario this works for me too as a workaround Hello Since I have updated my angularfire2 to t...
19
angularfire automaticDataCollectionEnabled' is missing in type 'FirebaseApp'
Same issue solved as suggested above.. At first Version info Angular: 5.2.9 Firebase: ^4.13.0 Angula...
17
angularfire Angular Ivy 9.0 stable and angularfire RC1 using Firestore have trouble with Universal
I am aiming to achieve success bundling us with Angular 9 SSR within a week Depending on the day of ...
16
angularfire Unhandled Promise rejection: this._next is not a function : Zone in @angular/fire/messaging
this worked for me: When I am receiving firebase push notifications in the foreground by using @angu...
15
angularfire Feature Request: Official version to delete a collection and all nested documents
There's no angularfire version You'd have to access the native Firestore SDK references: The above e...
15
angularfire FireStore timestampsInSnapshots
you can try but i dont know if it work : and comment: AngularFirestoreModule.enablePersistence() ...
15
angularfire Module '"/node_modules/angularfire2/angularfire2"' has no exported member 'AngularFireModule'.
@lfarroco @DMPS Can you try the pre-release version? I am trying to use the latest version of Angula...
13
angularfire How do I iterate through FirebaseListObservable<[]> object
Hi As this.users will get its data asynchronously from firebase you're likely trying to iterate befo...
11
angularfire AngularFire is not compatible with Firebase JS SDK v8
I still can't get auth and User by importing firebase/app It just says it doesn't have an exported m...
10
angularfire Can't run npm install angularfire2 firebase --save
I believe this issue is due to the latest version of firebase is now 4.0.0 but angularfire2@4.0.0-rc...
8
angularfire signInWithCredential error code auth/network-request-failed
Hi I have had the same problem with signInWithCredential which returns an error code auth/network-re...
6
angularfire Server Error. certificate has expired
I'm not super familiar with AngularFire but I'm pretty sure I found the issue ** Screenshots ** Expe...
3
angularfire Uncaught Error: "location.protocol" must be http or https when building to device using Ionic 2 & Angular 2
here is a project where I am running into issues - https://github.com/aaronksaunders/ionic2-angularf...
885
components Error: mat-form-field must contain a MatFormFieldControl.
You have to add to app.module.ts: Bug feature request or proposal: When doing a karma/jasmine test I...
608
angular Angular5.x lazyLoad problem, undefined is not a function
For others that find this issue via Google as i did: I had the same problem when trying to lazy load...
348
angular Cyclic dependency error with HttpInterceptor
I resolved simply not setting authService in constructor but getting in the intercept function. ...
286
angular cli Issue: Cannot read property 'thisCompilation' of undefined
Here is the answer from issues #9793 : npm remove webpack npm install webpack@3.11.0 ...
277
angular Uncaught Error: Can't resolve all parameters for ...
You are missing an @Injectable() annotation on your ApiService Support requests like these should li...
275
ngx bootstrap fix(tooltip): tooltip flickering when hover the mouse on the border on the tooltip position
Add pointer-events: none; to the tooltip css problem solved! .tooltip { pointer-events: none; } ...
266
angular Force reload/refresh current route with RouteReuseStrategy
Hi If you really need to trick the Router into reloading the component on each routerLink click ...
260
angular Misleading error message "Cannot find a differ supporting object '[object Object]'"
I just ran into the same issue I'm not sure if the recommended solution will work for my case ...
255
angular cli Error | Could not find plugin "proposal-numeric-separator" | Generating ES5 bundles for differential loading
Try to install @babel/compat-data: ~7.8.0 to devDependencies This is the only workaround which helpe...
246
sheetjs How to simply export a Worksheet to xlsx?
There are two issues: each object is mapped to a row so if you want a row with name John and city Se...
236
angular cli Using invalid environment causes error in build (was "ERROR in Cannot read property 'length' of undefined")
Probably not the same cause but we had the same error (Cannot read property 'length' of undefined) w...
232
angular cli ng serve method ip not open in another machines
The solution is simple Just bind to the correct interface address via ng serve --host=0.0.0.0 ...
226
angular cli Incorrect JS paths when ng build -prod is deployed in a subfolder
When you're deploying to non-root path within a domain you'll need to manually update the <base href...
224
angular update 2 to 4 has problem [ts] Property 'map' does not exist on type 'Observable<Response>'.
I met the same problem with the angular cli 6.0.0 and rxjs 6.1.0 And I solved the problem by replaci...
218
angular cli Installation error: permission denied for node-sas
sudo npm install -g --unsafe-perm --verbose @angular/cli Installation error (node-sass) with: node v...
208
angular cli ng build -prod Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
Instead of use ng build --prod use ng build --env=prod UPDATE As many of us (thx) have mention this ...
175
storybook Webpack 4 support?
I'm getting the below error when running Storybook with a project using Webpack 4; This is preventin...
173
angular cli Property 'controls' does not exist on type 'AbstractControl'.
Got it! Looked at the docs - FormArray The FormArray class contains the controls property ...
170
angular Angular2 AoT Compiler Errors
pls try /cc @chuckjaz When I try to compile my project with ngc it throws the below error: Error: Er...
167
angular cli [Bug] cli needs to be reloaded when a lazy loaded module is added in routes (FIXED)
I recomended change { path: 'user-panel' loadChildren: './user-panel/user-panel.module#UserPanelModu...
167
prettier Change HTML/JSX formatting to have one attribute/prop per line
The point I am trying to make is that the vertical space matters Wasting it (too much) has negative ...
162
angular cli AOT build fails
I noticed same problem and after npm i enhanced-resolve@3.3.0 I can build with AOT ...