angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.71k stars 2.18k forks source link

Error: Uncaught (in promise): TypeError: Failed to resolve module specifier 'firebase/auth' #2390

Closed SiddAjmera closed 4 years ago

SiddAjmera commented 4 years ago

Version info

Angular:

9.1.0

Firebase:

7.13.2

AngularFire:

Tried with both 6.0.0 and 6.0.0-rc.2

Other (e.g. Ionic/Cordova, Node, browser, operating system):

I'm using this on StackBlitz.

How to reproduce these conditions

Failing test unit, Plunkr, or JSFiddle demonstrating the problem

https://stackblitz.com/edit/kittygram-oauth

Steps to set up and reproduce

Sample data and security rules

<-- include/attach/link to some json sample data (or provide credentials to a sanitized, test Firebase project) -->

Debug output

Errors in the JavaScript console

Error: Uncaught (in promise): TypeError: Failed to resolve module specifier 'firebase/auth'
TypeError: Failed to resolve module specifier 'firebase/auth'
at eval (https://kittygram-oauth.stackblitz.io/turbo_modules/@angular/fire@6.0.0/bundles/angular-fire-auth.umd.js:26:27)
at ZoneDelegate.invoke (https://kittygram-oauth.stackblitz.io/turbo_modules/zone.js@0.10.3/dist/zone.js:386:30)
at Zone.run (https://kittygram-oauth.stackblitz.io/turbo_modules/zone.js@0.10.3/dist/zone.js:143:47)
at NgZone.runOutsideAngular (https://kittygram-oauth.stackblitz.io/turbo_modules/@angular/core@9.1.0/bundles/core.umd.js:27926:32)
at SwitchMapSubscriber.eval [as project] (https://kittygram-oauth.stackblitz.io/turbo_modules/@angular/fire@6.0.0/bundles/angular-fire-auth.umd.js:23:39)
at SwitchMapSubscriber._next (https://kittygram-oauth.stackblitz.io/turbo_modules/rxjs@6.5.5/internal/operators/switchMap.js:49:27)
at SwitchMapSubscriber.Subscriber.next (https://kittygram-oauth.stackblitz.io/turbo_modules/rxjs@6.5.5/internal/Subscriber.js:66:18)
at Notification.observe (https://kittygram-oauth.stackblitz.io/turbo_modules/rxjs@6.5.5/internal/Notification.js:22:50)
at QueueAction.ObserveOnSubscriber.dispatch (https://kittygram-oauth.stackblitz.io/turbo_modules/rxjs@6.5.5/internal/operators/observeOn.js:48:22)
at eval (https://kittygram-oauth.stackblitz.io/turbo_modules/@angular/fire@6.0.0/bundles/angular-fire.umd.js:262:26)

Expected behavior

It should not ask to install @firebase/app

Actual behavior

It alerted saying that @firebase/app is not installed and prompted to install it. Once I did, I threw the error mentioned above when I tried to call this.afAuth.signInWithPopup(new auth.GoogleAuthProvider());

jamesdaniels commented 4 years ago

I've heard complaints with StackBlitz here, I'll be looking into that environment shortly.

jamesdaniels commented 4 years ago

Out of curiosity does it work if you short circuit lazy loading of the auth sdk?

Just import 'firebase/auth' yourself.

SiddAjmera commented 4 years ago

I'm actually doing that already in my auth.service.ts but doesn't help.

wasun26 commented 4 years ago

try to use import firebase from 'firebase'; instead of @angular/fire/auth look like new version of angular/fire/auth not match or support to current firebase version. I use this import it work fine.

Unkn0wn0x commented 4 years ago

From your Stackblitz app-firebase.module.ts, try to import following dependencies:

import { AngularFireAuthModule } from "@angular/fire/auth";
import { AngularFireModule } from "@angular/fire";
import { NgModule } from "@angular/core";
import 'firebase/auth';
// Additional imports for example ...
//import 'firebase/database'
//import 'firebase/storage';

import { environment } from "../environments/environment";

@NgModule({
  imports: [AngularFireModule.initializeApp(environment.firebase)],
  exports: [AngularFireAuthModule, AngularFireModule]
})
export class AppFirebaseModule {}

Please refer to the Changelog:

Hope it helps.

Cheers Unkn0wn0x

weilies commented 4 years ago

i hit the same error. anyone know what exact code changes to make it work again?

arikanorh commented 4 years ago

I am also having this problem. The code in docs doesnt work

EricSimons commented 4 years ago

Hey all- I think it's due to an import() call inside the UMD bundle, which should get converted to CJS require(). thread

@jamesdaniels is there a future release coming that would fix this? Can also try to get something implemented on our side as well.

Edit: This should now be working. Feel free to close if you're seeing the same on your end!

arikanorh commented 4 years ago

@EricSimons

I've just checked and this is still the case for me

image

You can check the project https://over-track.stackblitz.io/

arikanorh commented 4 years ago

@EricSimons This looks fixed now. I can sucesfully login with firebase auth now. Ty Eric

weilies commented 4 years ago

hi @arikanorh GREAT to hear that! could you share the working code to import firebase/auth?

Thanks!

arikanorh commented 4 years ago

Hello I've added following import to my app.module

import 'firebase/auth'; Then used FirebaseAuth just as documented

import { AngularFireAuth } from '@angular/fire/auth'; I'd like to share the source code but it has some private information sorry. I can helo you further if you have any problems

weilies commented 4 years ago

lol, i tried to build a POC by create new project in StackBlitz. But i think thing jz get little complicated as now all angular project defaulted with Ivy, and it compile differently using ngcc.

now i getting a different error.

Error in ~/src/main.ts
ngcc failed to run on @angular/fire@6.0.0.

then it refresh with another error

Error in turbo_modules/@angular/fire@6.0.0/auth/auth.d.ts (8:22)
Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the dependency (@angular/fire/auth) which declares AngularFireAuth has not been processed correctly by ngcc.

here my project: https://stackblitz.com/edit/angular-ivy-wemptx feel free to fork it.

arikanorh commented 4 years ago

Here is my working app. You can have a look at

https://stackblitz.com/edit/over-track

weilies commented 4 years ago

hi @arikanorh ! thanks for the GREAT reference. Here my summary to use firebase auth v6.0.0, for the import to work for me

app.module.ts

import { environment } from "../environments/environment";
import { AngularFireModule } from "@angular/fire";
import { AngularFireAuthModule } from "@angular/fire/auth";
import { AngularFirestoreModule } from "@angular/fire/firestore";

your user/auth service file

import { auth, firestore } from "firebase/app";
import { AngularFireAuth } from "@angular/fire/auth";
import { AngularFirestore } from "@angular/fire/firestore";

service constructor constructor(public auth: AngularFireAuth) {} login/logout logic

  onLogin() {
    this.auth.signInWithPopup(new auth.GoogleAuthProvider()).then(res => {
      // list of signed in logics
      console.log(res);
    });
  }

  onLogout() {
    this.auth.signOut().then(res => {
      // list of signed out in logics
      console.log("list of signout logic");
    });
  }

For a non JS/TS expert, i struggling to various types of import, firebase/auth, firebase, @angular/fire/auth, frankly i cant imagine how crazy the magic done behind :) but really thanks to the community's great support!! @EricSimons , @arikanorh !

GaurangDhorda commented 4 years ago

Today I am figured out that https://stackblitz.com/edit/angular-ivy-tmcsfk?file=src%2Fapp%2Fapp.component.ts Authentication working properly now with stackblitz. we need import { auth } from 'firebase/app'; import 'firebase/auth';

jamesdaniels commented 4 years ago

Should not be an issue anylonger with the newer versions of the libs. Firebase v8 cleaned this up a lot.