【问题标题】:Property 'functions' does not exist on type 'FirebaseApp'“FirebaseApp”类型上不存在属性“函数”
【发布时间】:2018-09-21 20:39:45
【问题描述】:

我一直在尝试使用 Firebase Documentation 中所述的可调用语法从我的 Ionic 应用程序调用 Firebase Cloud Functions

我还在 StackOverflow 中找到了以前的 question,这似乎是我一直在寻找的正确答案...

我遇到的问题是我无法使用“ionic build”构建代码,因为它给了我以下错误:Property 'functions' does not exist on type 'FirebaseApp'

我的代码如下所示:

import firebase from 'firebase';
import '@firebase/functions';
import { ConfigSettings } from '../shared/app.config';

const firebaseApp = firebase.initializeApp(ConfigSettings);
const functions = firebaseApp.functions();

这是我的 package.json 中的依赖项:

"dependencies": {
  "@angular/common": "5.0.3",
  "@angular/compiler": "5.0.3",
  "@angular/compiler-cli": "5.0.3",
  "@angular/core": "5.0.3",
  "@angular/forms": "5.0.3",
  "@angular/http": "5.0.3",
  "@angular/platform-browser": "5.0.3",
  "@angular/platform-browser-dynamic": "5.0.3",
  "@firebase/functions": "^0.1.0",
  "@ionic-native/contacts": "^4.6.0",
  "@ionic-native/core": "4.4.0",
  "@ionic-native/facebook": "^4.5.3",
  "@ionic-native/firebase-dynamic-links": "^4.6.0",
  "@ionic-native/google-plus": "^4.5.3",
  "@ionic-native/social-sharing": "^4.6.0",
  "@ionic-native/splash-screen": "4.4.0",
  "@ionic-native/status-bar": "4.4.0",
  "@ionic/pro": "1.0.20",
  "@ionic/storage": "^2.1.3",
  "angularfire2": "^5.0.0-rc.6",
  "cordova-android": "6.4.0",
  "cordova-plugin-contacts": "^3.0.1",
  "cordova-plugin-device": "^2.0.1",
  "cordova-plugin-facebook4": "^1.9.1",
  "cordova-plugin-firebase-dynamiclinks": "^0.13.1",
  "cordova-plugin-googleplus": "^5.2.1",
  "cordova-plugin-ionic-keyboard": "^2.0.5",
  "cordova-plugin-ionic-webview": "^1.1.16",
  "cordova-plugin-splashscreen": "^5.0.2",
  "cordova-plugin-whitelist": "^1.3.3",
  "cordova-plugin-x-socialsharing": "^5.3.2",
  "cordova-sqlite-storage": "^2.2.1",
  "cordova-support-google-services": "^1.1.0",
  "cors": "^2.8.4",
  "es6-promise-plugin": "^4.2.2",
  "firebase": "^4.12.1",
  "ionic-angular": "3.9.2",
  "ionicons": "3.0.0",
  "rxjs": "5.5.2",
  "sw-toolbox": "3.6.0",
  "zone.js": "0.8.18"
}

【问题讨论】:

    标签: firebase ionic-framework google-cloud-functions


    【解决方案1】:

    您不应该尝试将 @firebase/functions 包与您的 Ionic 应用程序一起编译。

    函数在本地调用以测试您的构建 - 它们不应与您的应用捆绑在一起。编译您的应用程序时,您将通过正确的方法(例如实时数据库触发器或 HTTP 触发器)调用您的函数,而不是使用 @firebase/functions 包。

    您链接到的说明 用于在您的开发环境中进行设置。这些与您的应用程序构建是分开的——也许您应该尝试将这些独立文件放在您的 Ionic 应用程序之外的单独目录中,这样它们就不会混淆。

    【讨论】:

    • 这似乎有点误导。该文档明确指出,您可以通过 HTTP 或通过其内部 API 包装器 (firebase.functions()) 调用函数。 npm firebase 包中肯定存在问题,因为它没有正确导入函数模块的类型,因此出现问题。现在,你可以称之为 firebaseApp['functions']()
    猜你喜欢
    • 2021-11-13
    • 2021-11-16
    • 2020-08-02
    • 2021-11-30
    • 2016-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    相关资源
    最近更新 更多