Angular 6 SSR build issue
Hi Team,
I am new in AngularFire2 library. I am getting one issue while making ssr build only. If i am running ng run build:ssr then i am getting some warnings.
WARNING in ./node_modules/angularfire2/firebase.app.module.js 15:22-26 "export 'apps' was not found in 'firebase/app' @ ./node_modules/angularfire2/firebase.app.module.js @ ./node_modules/angularfire2/public_api.js @ ./node_modules/angularfire2/index.js @ ./dist/server/main.js @ ./server.ts
WARNING in ./node_modules/angularfire2/firebase.app.module.js 16:27-40 "export 'initializeApp' was not found in 'firebase/app' @ ./node_modules/angularfire2/firebase.app.module.js @ ./node_modules/angularfire2/public_api.js @ ./node_modules/angularfire2/index.js @ ./dist/server/main.js @ ./server.ts
But after running npm run serve:ssr, i am getting this error
TypeError: Cannot read property 'filter' of undefined at _firebaseAppFactory (E:\dev\migration\dist\server.js:206291:73) at E:\dev\migration\dist\server.js:210811:95 at ZoneDelegate.invoke (E:\dev\migration\dist\server.js:527:26) at Zone.run (E:\dev\migration\dist\server.js:277:43) at NgZone.runOutsideAngular (E:\dev\migration\dist\server.js:7898:28) at new AngularFireAuth (E:\dev\migration\dist\server.js:210810:26) at _createClass (E:\dev\migration\dist\server.js:13149:20) at _createProviderInstance$1 (E:\dev\migration\dist\server.js:13111:26) at resolveNgModuleDep (E:\dev\migration\dist\server.js:13077:21) at _createClass (E:\dev\migration\dist\server.js:13143:107)
Because of this error i am unable to migrate from Angular 5 to Angular 6. Please help
I'm having the same issue with version [email protected], if you use 5.0.0-rc.9 it does not happen (same firebase version "firebase": "^5.0.4" for both cases). The affected line is the one with "var existingApp":
function _firebaseAppFactory(options, nameOrConfig) {
var name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
var config = typeof nameOrConfig === 'object' && nameOrConfig || {};
config.name = config.name || name;
var existingApp = firebase_app__WEBPACK_IMPORTED_MODULE_1__["apps"].filter(function (app) { return app && app.name === config.name; })[0];
return (existingApp || Object(firebase_app__WEBPACK_IMPORTED_MODULE_1__["initializeApp"])(options, config));
}
Doing a console.log of "firebase_app__WEBPACK_IMPORTED_MODULE_1__" shows:
firebase_app__WEBPACK_IMPORTED_MODULE_1__ { default:
{ __esModule: true,
initializeApp: [Function: initializeApp],
app: { [Function: app] App: [Function: FirebaseAppImpl] },
apps: [Getter],
Promise:
....
I'll check on this + put in an SSR test to make sure we don't regress in future releases.
Any solution to this yet?
I am actually using that! But am still getting the error.
Unhandled Promise rejection: Cannot read property 'filter' of undefined ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'filter' of undefined
at _firebaseAppFactory (webpack:///./node_modules/angularfire2/firebase.app.module.js?:23:73)
at eval (webpack:///./node_modules/angularfire2/firestore/firestore.js?:33:95)
at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone-node.js?:387:26)
at Zone.run (webpack:///./node_modules/zone.js/dist/zone-node.js?:137:43)
at NgZone.runOutsideAngular (webpack:///./node_modules/@angular/core/fesm5/core.js?:3902:28)
at new AngularFirestore (webpack:///./node_modules/angularfire2/firestore/firestore.js?:32:31)
at _createClass (webpack:///./node_modules/@angular/core/fesm5/core.js?:8398:20)
at _createProviderInstance$1 (webpack:///./node_modules/@angular/core/fesm5/core.js?:8360:26)
at initNgModule (webpack:///./node_modules/@angular/core/fesm5/core.js?:8296:32)
at new NgModuleRef_ (webpack:///./node_modules/@angular/core/fesm5/core.js?:9019:9) TypeError: Cannot read property 'filter' of undefined
at _firebaseAppFactory (webpack:///./node_modules/angularfire2/firebase.app.module.js?:23:73)
at eval (webpack:///./node_modules/angularfire2/firestore/firestore.js?:33:95)
at ZoneDelegate.invoke (webpack:///./node_modules/zone.js/dist/zone-node.js?:387:26)
at Zone.run (webpack:///./node_modules/zone.js/dist/zone-node.js?:137:43)
at NgZone.runOutsideAngular (webpack:///./node_modules/@angular/core/fesm5/core.js?:3902:28)
at new AngularFirestore (webpack:///./node_modules/angularfire2/firestore/firestore.js?:32:31)
at _createClass (webpack:///./node_modules/@angular/core/fesm5/core.js?:8398:20)
at _createProviderInstance$1 (webpack:///./node_modules/@angular/core/fesm5/core.js?:8360:26)
at initNgModule (webpack:///./node_modules/@angular/core/fesm5/core.js?:8296:32)
at new NgModuleRef_ (webpack:///./node_modules/@angular/core/fesm5/core.js?:9019:9)
Fixed in rc.11

Same here. I still get this issue.

function _firebaseAppFactory(options, nameOrConfig) {
var name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
var config = typeof nameOrConfig === 'object' && nameOrConfig || {};
config.name = config.name || name;
var existingApp = firebase_app__WEBPACK_IMPORTED_MODULE_1__["apps"].filter(function (app) { return app && app.name === config.name; })[0];
return (existingApp || Object(firebase_app__WEBPACK_IMPORTED_MODULE_1__["initializeApp"])(options, config));
I am still getting this error. @jamesdaniels. But it is working for me in rc.9
I'm still getting the TypeError: Cannot read property 'filter' of undefined error @jamesdaniels :(
Hello, I am now getting the error myself when I try to build my ssr prerender using @angular/universal with the latest version of AF2. Funny enough it has been working all day. I just updated all my node modules. I usually do this every 4 - 6 hours. Not sure if that has anything to do with it.
Here is the complete and boring console log of the error step by step: console_error_log.txt
Thanks!
Why was this closed? This is still an occurring issue in RC.11. Using my own node server I still get this error. Any help or direction to a workaround or anything would be greatly appreciated. Thanks!
@jwuliger Can you try removing package-lock.json and running npm install again?
@gayankalhara Hello! Thanks for your reply. Yes, I have done that several times. I have tried Yarn and NPM, clearing cache and all that fun stuff. Just when I think I have found the issue, it reveals itself again in a different form. This must be something I am not configuring correctly. However I have done this several time before without issue. If I share my repo, would you be willing to take a peak? It not no worries! Thanks!
Using rc.11 i went to node_modules/angularfire2/firebase.app.module.js
I changed
import * as firebase from 'firebase/app';
to
import firebase from 'firebase/app';
I´m not sure how much of a fix this is but there seems to be a reference error to firebase/app.
This fixed the issue for me and prerendering works again.
it is not working yet..Anyone has a solution of it ?
@yugank1991 did you try the solution i posted above? Seems to have solved the issue for me.
@anasbaddyr I have tried with import firebase from 'firebase/app'; but it is giving error related to export
I have tried everything as well. All suggestions including the one from @yugank1991. Prerendering and SSR does not work with Firebase Hosting/Cloud Functions. I can't speak for anyone else but I am also not able to get it to work on my workstation using a simple NodeJS Server. I don't understand why this issue was closed as many people are having problems with it. Is there something that I am missing here? Is there a specific combination of pack age versions I should be using? Very eagerly awaiting for a solution to use either complete server-side rendering and or prerendering. Seems all other Frameworks and stacks do not have this issue. Please let me know if there is anything I can do. Thank you so much.
Update -
Found the issue for me. @yugank1991 Your solution was what led me to find out that I needed to add an additional import.
Instead of:
import * as firebase from 'firebase/app';
I changed the imports to:
import { firebase } from '@firebase/app';
import 'firebase/app';
Now I can run SSR on any Node server. I am still in the process of testing the firebase function for hosting. If you would like to see this working in real-time check out my Repo here:
@jwuliger unfortunately this is not working for me. Could you confirm the npm package that you are using and why do you need to import firebase that way ? to use messaging ?
Thanks