3

I am try to connect to database in firebase. Here is the app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '@ionic-native/splash-screen';
import { StatusBar } from '@ionic-native/status-bar';

import { AngularFireDatabase, AngularFireDatabaseModule } from 'angularfire2/database';

import { AngularFireModule } from 'angularfire2';
import { environment } from '../environments/environment';

import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';

@NgModule({
  declarations: [
    MyApp,
    HomePage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    AngularFireModule.initializeApp(environment.firebase),
    AngularFireDatabaseModule
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage
  ],
  providers: [
    AngularFireDatabase,
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]
})
export class AppModule {}

The error is in this line

import { AngularFireDatabase, AngularFireDatabaseModule } from 'angularfire2/database';

I have tried this also import { AngularFireDatabase, AngularFireDatabaseModule } from 'angularfire2/database-deprecated';

But the the error just change.

Runtime Error Cannot find module "angularfire2/database" Stack Error: Cannot find module "angularfire2/database" at Object.217 (http://localhost:8100/build/main.js:78:7) at webpack_require (http://localhost:8100/build/vendor.js:55:30) at Object.194 (http://localhost:8100/build/main.js:60:70) at webpack_require (http://localhost:8100/build/vendor.js:55:30) at webpackJsonpCallback (http://localhost:8100/build/vendor.js:26:23) at http://localhost:8100/build/main.js:1:1

2 Answers 2

1

Just read this documentation

in terminal: npm install firebase --save

In your app.module.ts create firebase config object:

// Set the configuration for your app
// TODO: Replace with your project's config object
var config = {
  apiKey: "apiKey",
  authDomain: "projectId.firebaseapp.com",
  databaseURL: "https://databaseName.firebaseio.com",
  storageBucket: "bucket.appspot.com"
};
firebase.initializeApp(config);

// Get a reference to the database service
var database = firebase.database();

After the call on Page .ts:

import * as firebase from 'firebase';
Sign up to request clarification or add additional context in comments.

4 Comments

I am actually a learner. So it would be good kindly describe me, why we need to add import * as firebase from 'firebase';
To Read and Write Data, See this firebase.google.com/docs/database/web/…
yes.. I got it what you saying.. But in ionic we use angularfire2 v5 to connect firebase. So is it good to use.
Use it example joshmorony.com/…
0

There is a problem with "angularfire2": "^5.0.0-rc.10" The solution for me was uninstall angularfire2^5.0.0-rc.10 and install angularfire2^5.0.0-rc.9

npm uninstall angularfire2
npm install [email protected]

I confirm this works, solution by @jsariasgeek

Issue discussion

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.