app.component:
import { AngularFireModule } from '@angular/fire';
import { AngularFirestoreModule } from 'angularfire2/firestore';
import { RoomComponent } from './component/room/room.component';
import { AngularFireAuth } from '@angular/fire/auth';
import { FirebaseService } from "./service/firebase.service";
import { AngularFireAuthModule } from 'angularfire2/auth';
imports: [
BrowserModule,
AngularFireModule.initializeApp(firebaseconfig),
AngularFirestoreModule
],
providers: [
FirebaseService,
{
provide: PERFECT_SCROLLBAR_CONFIG,
useValue: DEFAULT_PERFECT_SCROLLBAR_CONFIG
},
AngularFireAuth
],
package.json文件:
{
"dependencies": {
"@angular/animations": "^5.2.11",
"@angular/cdk": "^5.2.4",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/material": "^5.2.4",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"angularfire2": "^5.0.1",
"core-js": "^2.4.1",
"dateformat": "^3.0.3",
"firebase": "^5.5.1",
"rxjs": "^6.3.2",
"rxjs-compat": "^6.3.2",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "~1.7.4",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
}
在服务中无效的导入:
import { AngularFirestore, AngularFirestoreCollection,
AngularFirestoreDocument } from 'angularfire2/firestore';
import { AngularFireAuth } from '@angular/fire/auth';
import { auth } from 'firebase/app'
import { Observable } from 'rxjs';
我只包括了可能与错误有关的依赖项,但是如果我错过了某些事情,请告诉我。
我已经尝试了多个版本。确实可以,但是有错误。问题出在导入{auth}中,这使我可以登录到Firebase。我不知道问题是什么。有时会编译,有时则不会。这是我到目前为止使用的唯一一个版本组合,有时即使有错误也可以编译。其他版本只会破坏其他导入。
仅当我暂时删除auth导入然后将其放回然后保存时,项目才会编译。
答案 0 :(得分:0)
在您的app.module.ts中:
xjb
答案 1 :(得分:0)
我将从大文件开始,我只是说尝试删除您的node_modules
文件夹和package-lock.json
,然后重新运行命令npm install
。最重要的是,一些建议...
您的导入和文件不一致,我看到您从angularfire2
以及@angular/fire
导入。尽管它们实际上是同一回事,但仅仅是Angular团队正在迁移/迁移到@angular/fire
。运行npm uninstall angularfire2
,然后运行npm i @angular/fire
。最后,您应该这样更新您的app.component
(我想您的意思是app.module
)……
import { AngularFireModule } from '@angular/fire';
import { AngularFirestoreModule } from '@angular/fire/firestore';
import { RoomComponent } from './component/room/room.component';
import { AngularFireAuth } from '@angular/fire/auth';
import { FirebaseService } from "./service/firebase.service";
import { AngularFireAuthModule } from '@angular/fire/auth';
imports: [
BrowserModule,
AngularFireModule.initializeApp(firebaseconfig),
AngularFirestoreModule,
AngularFireAuthModule // IMPORT THE AUTH MODULE IF YOU'RE GOING TO USE IT
],
providers: [
FirebaseService,
{
provide: PERFECT_SCROLLBAR_CONFIG,
useValue: DEFAULT_PERFECT_SCROLLBAR_CONFIG
},
// AngularFireAuth (don't need/should not provide this, allow the module to set this up)
],
请记住,如果您有回购协议,并且希望我查看我可以提供更多帮助,我希望能够看到更多代码,但是希望这将是一个很好的开始/修复。 / p>
答案 2 :(得分:0)
使用此命令npm i @angular/fire
答案 3 :(得分:0)
npm install firebase
解决了我的问题