【问题标题】:Property 'automaticDataCollectionEnabled' is missing in type 'FirebaseApp'“FirebaseApp”类型中缺少属性“automaticDataCollectionEnabled”
【发布时间】:2018-04-22 06:33:59
【问题描述】:

我们用

安装了 angular firebase
npm install firebase angularfire2 --save

这个错误发生了

ERROR in node_modules/angularfire2/firebase.app.module.d.ts(10,22): error TS2420: Class 'FirebaseApp' incorrectly implements interface 'FirebaseApp'.
Property 'automaticDataCollectionEnabled' is missing in type 'FirebaseApp'.

我该如何解决?

【问题讨论】:

    标签: angular firebase angular2-services


    【解决方案1】:

    我会建议不要直接修改您的 node_modules。这是不必要且不好的做法,因为您的更改将被更新覆盖。

    在使用最新的firebase@4.13.1angularfire2@5.0.0-rc.6 的组合时,似乎会出现 Op 的错误。

    解决方案:

    有些人建议降级 firebase 软件包,但更好的选择可能是安装 @firebase/app@^0.1.10 以修复我的错误。

    注意:

    最新的 firebase 4.13.1 对 Firestore Timestamp/Date 对象进行了一些更改,我已经实现了这些更改,如果降级 firebase 包,则必须还原。

    【讨论】:

    • 你是对的!安装“angularfire2”:“^5.0.0-rc.7.0-next”,编译成功。谢谢!
    • 我不得不安装angularfire2@next (5.0.0-rc.7.0-next),没有用。然后安装了@firebase/app@^0.1.10,它成功了!有趣的是,我在使用ng set defaults.styleExt scss 将样式更改为 sass 并重命名文件后立即停止工作,想知道这是否改变了某些包版本?
    • @JasonGoemaat 如何停止工作?我正在使用具有上述配置的 Firebase 身份验证。
    【解决方案2】:

    这对我有用。编辑 firebase.app.module.d.ts 文件

    export declare class FirebaseApp implements FBApp {
    name: string;
    options: {};
    automaticDataCollectionEnabled: boolean; // this is the missing line
    auth: () => FirebaseAuth;
    database: () => FirebaseDatabase;
    messaging: () => FirebaseMessaging;
    storage: () => FirebaseStorage;
    delete: () => Promise<any>;
    firestore: () => FirebaseFirestore;
    }
    

    同时添加@firebase/app

    npm i -S @firebase/app
    

    编辑

    安装"angularfire2": "^5.0.0-rc.7"解决问题

    只需运行npm install angularfire2@latest

    【讨论】:

    • 现在它显示“模块 /opt/lampp/htdocs/admin/node_modules/angularfire2/index.d.ts 元数据版本不匹配错误,找到版本 4,预期 3,解析符号 AppModule 在 / opt/lampp/htdocs/admin/src/app/app.module.ts,解析/opt/lampp/htdocs/admin/src/app/app.module.ts中的符号AppModule,解析/opt/lampp/中的符号AppModule htdocs/admin/src/app/app.module.ts"
    • @Midhilaj 你有哪个版本的 angularfire2?我正在使用 5.0.0-rc.6.0。
    • "angularfire2": "^5.0.0-rc.6",
    • 你安装了@firebase/app 吗?
    • 我们试图从creative-tim.com/product/material-dashboard-pro-angular2 在这个模板md-pro-angular.creative-tim.com/… 中安装firebase,我们尝试了很多次,我们放弃了这个尝试。我们开始使用 mdl 创建自己的管理模板。如果您找到在 angular 2 中使用带有上述管理员免费模板的 firebase 的解决方案,请通知我
    【解决方案3】:

    尝试在 package.json 中使用这些依赖项

    "dependencies": {
     "firebase":"4.12.1",
     "angularfire2":"^5.0.0-rc.6",
     "@firebase/app": "^0.1.10" 
    }
    

    【讨论】:

    • 这对我有用。但如果我对@firebase/app 使用最新的^0.2.0,它就会失败。
    • 这对我有用,虽然我没有更改@firebase/app,因为我没有使用它,只是 firebase 和 angularfire2。谢谢!
    【解决方案4】:

    当我将 firebase 升级到 4.13.1 时发生这种情况

    为了解决这个问题,我将 angularfire2 更新为 ^5.0.0-rc.7.0-next

    我的依赖看起来像:

    "dependencies":{
    "angularfire2": "^5.0.0-rc.7.0-next",
    "firebase": "^4.13.1",
    }
    

    【讨论】:

    • 这对我有用,即使没有添加 @firebase/app 作为直接依赖项。可能会有关于未来弃用日期的警告(如果您使用的是updated_atcreated_at),但很容易涵盖这一点。
    【解决方案5】:

    你也可以改变 node_modules\angularfire2\firebase.app.module.d.ts

    之前

    export declare class FirebaseApp implements FBApp {
        name: string;
        options: {};
        auth: () => FirebaseAuth;
        database: () => FirebaseDatabase;
        messaging: () => FirebaseMessaging;
        storage: () => FirebaseStorage;
        delete: () => Promise<any>;
        firestore: () => FirebaseFirestore;
    }
    

    之后

    export declare class FirebaseApp implements FBApp {
        name: string;
        automaticDataCollectionEnabled: boolean;
        options: {};
        auth: () => FirebaseAuth;
        database: () => FirebaseDatabase;
        messaging: () => FirebaseMessaging;
        storage: () => FirebaseStorage;
        delete: () => Promise<any>;
        firestore: () => FirebaseFirestore;
    }
    

    它应该解决这个问题,直到 angularfire 提出解决方案:)

    编辑

    Angularfire2 应该附带一个解决方案 tmrw,所以我会考虑设置一个计时器来明天更新库 :) https://github.com/angular/angularfire2/issues/1576

    【讨论】:

    • 现在它显示“模块 /opt/lampp/htdocs/admin/node_modules/angularfire2/index.d.ts 元数据版本不匹配错误,找到版本 4,预期 3,解析符号 AppModule 在 / opt/lampp/htdocs/admin/src/app/app.module.ts,解析/opt/lampp/htdocs/admin/src/app/app.module.ts中的符号AppModule,解析/opt/lampp/中的符号AppModule htdocs/admin/src/app/app.module.ts"
    【解决方案6】:

    尝试通过 cli 回滚

    npm install @firebase/app@0.1.10
    

    【讨论】:

    • 现在它在 ./~/angularfire2/firebase.app.module.js 中显示
      WARNING 3:40-54 "export 'InjectionToken' was not found in '@angular/core' WARNING在 ./~/angularfire2/angularfire2.js 4:26-40 “在模块的元数据版本不匹配中的“@angular/core”中找不到导出“InjectionToken”
    • 我建议清理一下,这样可以消除不匹配的情况。 npm 缓存清理并从头开始
    • 问题已解决
      npm uninstall angularfire2 firebase --save
      npm install angularfire2@5.0.0-rc.3 --save
      npm install firebase --保存
    【解决方案7】:

    如果您使用 AngularFire 5.0.0-rc.3 与任何大于 4.6.0 的 firebase 版本不兼容

    所以将这些添加到 package.json 中

    "angularfire2": "5.0.0-rc.3", "firebase": "4.6.0",
    

    然后运行npm install

    【讨论】:

    • 问题已解决
      npm uninstall angularfire2 firebase --save
      npm install angularfire2@5.0.0-rc.3 --save
      npm install firebase --保存
    • 祝你好运......干杯!
    【解决方案8】:

    我得到同样的错误:

    node_modules/angularfire2/firebase.app.module.d.ts(10,22) 中的错误:错误 TS2420:“FirebaseApp”类错误地实现了“FirebaseApp”接口。 “FirebaseApp”类型中缺少属性“automaticDataCollectionEnabled”。

    解决方案是将 FBapp 实现为“firebase.app.module/ts”。为此添加以下代码:

    "automaticDataCollectionEnabled: boolean;"
    

    在 firebase.app 文件中放入 FBApp 部分

    【讨论】:

      猜你喜欢
      • 2019-09-20
      • 2019-09-19
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      • 2015-12-02
      • 2019-02-07
      • 2016-11-22
      • 2020-07-05
      相关资源
      最近更新 更多