angular - firebase_app__WEBPACK_IMPORTED_MODULE_5__.app(...).functions 不是函数
问题描述
"@angular/core": "~9.1.2",
"@angular/fire": "^5.1.1",
"firebase": "^7.24.0",
createPortalLink()
正在工作的 js 代码导入到 Angular,但它会生成 TypeError。如何修复 TypeError?
类型错误:firebase_app__WEBPACK_IMPORTED_MODULE_5__.app(...).functions 不是函数
import * as firebase from 'firebase/app';
async createPortalLink() {
// Call billing portal function
const functionLocation = 'us-central1';
const functionRef = firebase
.app()
.functions(functionLocation)
.httpsCallable('ext-firestore-stripe-subscriptions-createPortalLink');
const { data } = await functionRef({ returnUrl: window.location.origin });
window.location.assign(data.url);
}
core.js:6210 ERROR Error: Uncaught (in promise): TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_5__.app(...).functions is not a function
TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_5__.app(...).functions is not a function
at BillingService.<anonymous> (billing.service.ts:52)
at Generator.next (<anonymous>)
at tslib.es6.js:73
at new ZoneAwarePromise (zone-evergreen.js:960)
at __awaiter (tslib.es6.js:69)
at BillingService.callBillingPortalFunction (billing.service.ts:47)
at BillingComponent.<anonymous> (billing.component.ts:77)
at Generator.next (<anonymous>)
at tslib.es6.js:73
at new ZoneAwarePromise (zone-evergreen.js:960)
at resolvePromise (zone-evergreen.js:798)
at zone-evergreen.js:705
at rejected (tslib.es6.js:71)
at ZoneDelegate.invoke (zone-evergreen.js:364)
at Object.onInvoke (core.js:41731)
at ZoneDelegate.invoke (zone-evergreen.js:363)
at Zone.run (zone-evergreen.js:123)
at zone-evergreen.js:857
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Object.onInvokeTask (core.js:41709)
解决方案
你需要import 'firebase/functions'
;
像这样
import * as firebase from 'firebase/app';
import 'firebase/functions';
async createPortalLink() {
// Call billing portal function
const functionLocation = 'us-central1';
const functionRef = firebase
.app()
.functions(functionLocation)
.httpsCallable('ext-firestore-stripe-subscriptions-createPortalLink');
const { data } = await functionRef({ returnUrl: window.location.origin });
window.location.assign(data.url);
}
或者试试这个(取决于你的版本):
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import 'firebase-functions';
admin.initializeApp();
推荐阅读
- ruby-on-rails - 比较 2 种不同格式的日期以匹配或不匹配 Ruby on Rails 6
- reactjs - 如何将 react-app-rewired 与 webpack 开发服务器一起使用?
- python - MySQL在python中选择多个变量
- python - 加快 pandas 计算
- angular - Angular Paginator 分页页面大小选项选择在页面下方
- codeigniter - Infinityfree.net 和 codeigniter
- sql - SQL-当连接不涵盖它们时,如何添加与ID直接对应的命名列
- php - 更改查看购物车按钮以添加到购物车按钮
- amazon-web-services - AWS API Gateway (REST) - 即使存在未知属性,请求验证也会通过
- sql - SSRS 表达式仅每天获取 2% 报告