firebase initializeApp fails `“projectId” not provided in firebase.initializeApp.`

4,251 views
Skip to first unread message

Sapan Parikh

unread,
Nov 1, 2017, 2:33:05 AM11/1/17
to Firebase Google Group
I am following this guide hosted at https://github.com/angular/angularfire2/blob/master/docs/install-and-setup.md to try out firestore and it seems I can't get past the setup stage. 
I have already installed firebase using npm and have imported it to appModule like the following 

    import {AngularFireModule} from "angularfire2";
    import {AngularFirestoreModule} from "angularfire2/firestore";
These imports are successfully resolving in IntelliJ plus my node_modules directory has the angularfire2 and angularfire2/firestore folders, so I conclude that node install was successful.
used it in import like the following

    imports: [
            BrowserModule,
            FormsModule,
            HttpClientModule,
            HttpModule,
            AppRoutingModule,
            NgbModule.forRoot(),
            AngularFireModule.initializeApp(firebaseConfig),
            AngularFirestoreModule,
    
        ]

where firebaseConfig(copied and pasted from the console) I have tried keeping in the environment.ts as well as a variable in app.module.ts

After doing this when I try to use it in a service I get the following error

    ERROR Error: Uncaught (in promise): FirebaseError: [code=invalid-argument]: "projectId" not provided in firebase.initializeApp.
    FirebaseError: "projectId" not provided in firebase.initializeApp.

The service looks like the following

    @Injectable()
    export class ClientsService {
        _clients: any;
    
    constructor(private db:AngularFirestore) {
        this._clients = this.db.collection('clients').valueChanges();
    }
    
        getClients(): Observable<any> {
             this._clients = this.db.collection('clients').valueChanges();
    
            return this._clients;
        }
    
    }

 Here is the firebaseConfig var

    var firebaseConfig = {
        apiKey: "copied from firebase console",
        authDomain: "something.firebaseapp.com",
        databaseURL: "https://something.firebaseio.com",
        projectId: "copied from firebase console",
        storageBucket: "something.appspot.com",
        messagingSenderId: "copied from firebase console"

     }

Kato Richardson

unread,
Nov 2, 2017, 12:26:20 AM11/2/17
to Firebase Google Group
Hi Sapan,

An initial guess would be that the config var isn't available at the time you declare it in your imports. Or if it's in a typescript definition, it may not be in scope when it gets evaluated.

You could validate that hypothesis by substituting the object into the config directly, instead of referencing a variable. E.g.

AngularFireModule.initializeApp({....}),

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/a4fc13ac-a8ab-4562-abc5-98878aa3bc5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages