[英]Angular 13: Namespace '"/node_modules/firebase/compat/index"' has no exported member 'User'. ts(2694)
1st error:第一个错误:
Namespace '"D:/desktop/Programming/oauthAngular/node_modules/firebase/compat/index"' has no exported member 'User'.
2nd error:第二个错误:
Type 'import("D:/desktop/Programming/oauthAngular/node_modules/rxjs/dist/types/internal/Observable").Observable<firebase.default.auth.UserCredential>' is not assignable to type 'import("D:/desktop/Programming/oauthAngular/node_modules/rxjs/dist/types/internal/Observable").Observable<import("D:/desktop/Programming/oauthAngular/node_modules/@firebase/auth/dist/auth-public").UserCredential>'.
Property 'providerId' is missing in type 'firebase.default.auth.UserCredential' but required in type 'import("D:/desktop/Programming/oauthAngular/node_modules/@firebase/auth/dist/auth-public").UserCredential'.
Here is what is inside my auth.service.ts
这是我的
auth.service.ts
里面的内容
import { AngularFireAuth } from '@angular/fire/compat/auth';
import * as auth from 'firebase/auth';
import { BehaviorSubject, Observable, from } from 'rxjs';
import { Injectable } from '@angular/core';
import { switchMap } from 'rxjs/operators';
import * as firebase from 'firebase/app';
@Injectable({
providedIn: 'root',
})
export class AuthService {
private user: BehaviorSubject<
Observable<firebase.User>
> = new BehaviorSubject<Observable<firebase.User>>(null);
user$ = this.user
.asObservable()
.pipe(switchMap((user: Observable<firebase.User>) => user));
constructor(private afAuth: AngularFireAuth) {
this.user.next(this.afAuth.authState);
}
loginViaGoogle(): Observable<auth.UserCredential> {
return from(this.afAuth.signInWithPopup(new auth.GoogleAuthProvider()));
}
logout(): Observable<void> {
return from(this.afAuth.signOut());
}
}
Can you help me with the errors in my Angular code.你能帮我解决我的 Angular 代码中的错误吗? I was trying to connect it to Firebase for me to be able to use OAuth?
我试图将它连接到 Firebase 以便我能够使用 OAuth? Thank you.
谢谢你。
This error could be from mixing two similar libraries.此错误可能来自混合两个类似的库。
Try removing import * as auth from 'firebase/auth';
尝试
import * as auth from 'firebase/auth';
instead import UserCredential from the correct library.而是从正确的库中导入 UserCredential。
import { UserCredential } from "@angular/fire/auth";
//import { UserCredential } from "firebase/auth";
I had the same problem as yours, and seeing your Topic open here helped me to solve the problem, thanks in advance.我遇到了和你一样的问题,看到你的主题在这里打开帮助我解决了这个问题,在此先感谢。 Looking at your imports I saw that you used:
查看您的导入,我看到您使用了:
import * as firebase from 'firebase/app';
The correct would be正确的是
import * as firebase from 'firebase/auth';
Hope it helps, Hugs!希望对你有帮助,抱抱!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.