Angularfire2 seems to not load in ionic2
2.0.0-beta.6-preview
Angular: 2.2.1 Firebase: 3.6.1 AngularFire: 2.0.0-beta.6-preview Other (e.g. Ionic/Cordova, Node, browser, operating system): Cordova CLI: 6.4.0 Ionic Framework Version: 2.0.0-rc.3 Ionic CLI Version: 2.1.12 Ionic App Lib Version: 2.1.7 Ionic App Scripts Version: 0.0.44 ios-deploy version: 1.9.0 ios-sim version: 5.0.11 OS: macOS Sierra Node Version: v6.9.1 Xcode version: Xcode 8.1 Build version 8B62
How to reproduce these conditions
I'm trying to run angularfire after having the plain firebase library working (used only for login so far). I'm using ionic and ionic serve is not working. I'm getting this during ionic serve:
[19:04:51] ionic-app-scripts 0.0.44 [19:04:51] watch started ... [19:04:51] build dev started ... [19:04:51] clean started ... [19:04:51] clean finished in 4 ms [19:04:51] copy started ... [19:04:51] transpile started ... [19:04:55] build dev failed: Cannot read property 'indexOf' of undefined [19:04:55] copy finished in 3.41 s [19:04:55] watch ready in 3.43 s [19:04:55] dev server running: http://localhost:8100/
In the www/build folder the html and the js file are not there so the build is not completing.
Debug output
** Errors in the JavaScript console **
http://localhost:8100/build/main.css Failed to load resource: the server responded with a status of 404 (Not Found) (2) http://localhost:8100/build/main.js Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:8100/build/main.css Failed to load resource: the server responded with a status of 404 (Not Found)
Expected behavior
Site loads
Actual behavior
Site does not load because of missing js and html files when angular fire is just imported
@ix-xerri Seems like this is working as expected. I wrote quick code (not following best practices, but this should work for the purposes of this issue) and have pasted below for your reference. I've attached the service file as well as two pages, which shows the navigation. This should get you going. Let me know, if this doesn't works for you.
I am on Windows 10 with following versions.
Ionic version is 2.1.8 Cordova version is 6.4.0 node version is 6.9.1 npm version is 3.10.8
Snippet from my package.json
"dependencies": { "@angular/common": "2.1.1", "@angular/compiler": "2.1.1", "@angular/compiler-cli": "2.1.1", "@angular/core": "2.1.1", "@angular/forms": "2.1.1", "@angular/http": "2.1.1", "@angular/platform-browser": "2.1.1", "@angular/platform-browser-dynamic": "2.1.1", "@angular/platform-server": "2.1.1", "@ionic/storage": "1.1.6", "angularfire2": "^2.0.0-beta.6", "firebase": "^3.6.1", "ionic-angular": "2.0.0-rc.3", "ionic-native": "2.2.3", "ionicons": "3.0.0", "rxjs": "5.0.0-beta.12", "zone.js": "0.6.26" }, "devDependencies": { "@ionic/app-scripts": "0.0.45", "typescript": "2.0.6" },
home.ts
import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import { AuthService } from '../../providers/auth-service'; import { SuccessPagePage } from '../success-page/success-page';
@Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage {
constructor(public navCtrl: NavController, private _auth: AuthService) {}
signInWithFacebook(): void { this._auth.signInWithFacebook() .then(() => this.onSignInSuccess()); }
private onSignInSuccess(): void {
this.navCtrl.push(SuccessPagePage); }}
success-page.ts
import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import { AuthService } from '../../providers/auth-service'; import { HomePage } from '../home/home';
@Component({ selector: 'page-success-page', templateUrl: 'success-page.html' }) export class SuccessPagePage {
showLogoutButton: boolean = false; displayName: string;
constructor(public navCtrl: NavController, private _auth: AuthService) { this.displayName = this._auth.displayName(); }
logoutFacebook() { this.showLogoutButton = false; this._auth.signOut(); this.navCtrl.push(HomePage); }
}
auth-service.ts
import { Injectable } from '@angular/core'; import { AuthProviders, FirebaseAuth, FirebaseAuthState, AuthMethods } from 'angularfire2';
@Injectable() export class AuthService { private authState: FirebaseAuthState;
constructor(public auth$: FirebaseAuth) { this.authState = auth$.getAuth(); auth$.subscribe((state: FirebaseAuthState) => { this.authState = state; }); }
get authenticated(): boolean { return this.authState !== null; }
signInWithFacebook(): firebase.Promise
{ return this.auth$.login({ provider: AuthProviders.Facebook, method: AuthMethods.Redirect }); } signOut(): void { this.auth$.logout(); }
displayName(): string { if (this.authState != null) { return this.authState.facebook.displayName; } else { return ''; } }
}
What do you mean 'as expected'? Please have a look here. There are other users with the same issue. As explained by me AngularFireModule.initializeApp(firebaseConfig) line does not even complete the build so the ionic site does not load.
@ix-xerri When you posted your issue, I assumed, you're not able to run your Ionic app with AngularFire2 (specifically, you're not able to authenticate using angular fire2) and hence I pasted the snippet code above, as I am able to get it running on my machine locally. I did mention the various modules, along with their version numbers.
Now with the above link, you're referring to an issue which seems to be more of Ionic and not angularFire2. For me the AngularFireModule.initializeApp(firebaseConfig) line does load.
My repo is here, incase you want to have a look
Please correct me, if I am missing something.
My issue is that I'm not able to load the site correct. But because I initialise AngularFire, the build does not complete. Here is a snippet of my package.json
"dependencies": { "@angular/common": "2.1.1", "@angular/compiler": "2.1.1", "@angular/compiler-cli": "2.1.1", "@angular/core": "2.1.1", "@angular/forms": "2.1.1", "@angular/http": "2.1.1", "@angular/platform-browser": "2.1.1", "@angular/platform-browser-dynamic": "2.1.1", "@angular/platform-server": "2.1.1", "@ionic/app-scripts": "0.0.44", "@ionic/storage": "1.1.6", "angularfire2": "^2.0.0-beta.6", "firebase": "^3.6.1", "ionic-angular": "2.0.0-rc.3", "ionic-native": "2.2.3", "ionicons": "3.0.0", "rxjs": "5.0.0-beta.12", "zone.js": "0.6.21" }, "devDependencies": { "@ionic/app-scripts": "0.0.45", "@types/request": "0.0.30", "typescript": "2.0.6" },
Looks Ok. Do you want to share your repo, especially app.module.ts.
Here is my app.module.ts
import { NgModule } from '@angular/core'; import { IonicApp, IonicModule } from 'ionic-angular'; import { MyApp } from './app.component'; import { LoginPage } from '../pages/login/login'; import { ProfilePage } from '../pages/profile/profile'; import { ResetPasswordPage } from '../pages/reset-password/reset-password'; import { SignupPage } from '../pages/signup/signup'; import { AboutPage } from '../pages/about/about'; import { ContactPage } from '../pages/contact/contact'; import { HomePage } from '../pages/home/home'; import { TabsPage } from '../pages/tabs/tabs';
import { AngularFireModule } from 'angularfire2'; export const firebaseConfig = { apiKey: "proper info is enter in this object", authDomain: "xxx", databaseURL: "xxx", storageBucket: "xxx", messagingSenderId: "xxx" };
console.log(AngularFireModule);
@NgModule({ declarations: [ MyApp, LoginPage, ProfilePage, ResetPasswordPage, SignupPage, AboutPage, ContactPage, HomePage, TabsPage ], imports: [ IonicModule.forRoot(MyApp), AngularFireModule.initializeApp(firebaseConfig) ], bootstrap: [IonicApp], entryComponents: [ MyApp, LoginPage, ProfilePage, ResetPasswordPage, SignupPage, AboutPage, ContactPage, HomePage, TabsPage ], providers: [] }) export class AppModule {}
You app.module.ts looks good. Won't be able to decipher more from it. Do you want to share your repo. I can look into it.
Can't share it. Sorry but there are other users with the same issue.
I just tried using the firebase library alone and it works. Can write to a database no problem and there are no errors.
Great to hear, you have an option. See if you want to have a second look at my repo. AngularFire2 works pretty well.
@ix-xerri Did you use firebase library alone for the whole app or for initialising the app in app.module.ts to get it to work. I am still having this problem
@ix-xerri Did you use firebase library alone for the whole app or for initialising the app in app.module.ts to get it to work. I am still having this problem
@mukesh51 everything is the same with the app in ur repo yet the error still exist
didn't try to user angularfire after initialising. So far not angularfire is being used but will try it today!
Ok. Thanks. I will be expecting your response
Same error and the site is not building. I've been told that the app is not loading angularfire when dealing with the same issue but it is is node_modules and using
`import firebase from 'firebase';
import { AngularFire, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2'; import { Observable } from 'rxjs/Observable';`
inside /pages
@Demi-ob Do you want to share your repo. I can clone it locally to see if I am able to reproduce your issue.
@ix-xerri do you want to modify your above syntax as
import * as firebase from 'firebase';
What is that suppose to do? I still get build dev failed: Cannot read property 'indexOf' of undefined and the build does not finish
when you use this statement
import { NavController } from 'ionic-angular';
you're explicitly importing NavController object from 'ionic-angular'. Now, if you want to import another object from the same module, you try to add it in the same import statement by specifying the object, separating it with a comma.
What if you want to import everything in one go, that is where you use *. Hope that helps.
I tried it and got the same error