[英]How to resolve firebase deploy Parsing error: Cannot read file
[英]how to resolve a firebase Uncaught Error with ionic typescript?
我的代碼有問題。 我在離子項目中使用 Firebase 函數(使用打字稿)。 當我運行“firebase serve”時,我的 function 工作並且我可以獲得數據,但是當我在 ionic 中導出我的 function 時,我有這個錯誤:
未捕獲的錯誤:響應缺少數據字段。 在服務中的新 HttpsErrorImpl (index.cjs.js:58)。 (index.cjs.js:553) 在步驟 (tslib.es6.js:100) at Object.next (tslib.es6.js:81) at fulfilled (tslib.es6.js:71) at ZoneDelegate.invoke (zone -evergreen.js:359) 在 Object.onInvoke (core.js:39699) 在 ZoneDelegate.invoke (zone-evergreen.js:358) 在 Zone.run (zone-evergreen.js:124) 在 zone-evergreen.js :855
這是我的 firebase function:
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
const serviceAccount = require('../permissions.json')
const cors = require('cors')({ origin: true })
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://{'myUrl'}.firebaseio.com'
})
export const posts = functions.https.onRequest(async (request, response) => {
const docs = await admin.firestore().collection('posts').orderBy('date', 'desc').get()
cors(request, response, () => {})
response.json(
docs.docs.map((doc) => {
return {
postID: doc.id,
...doc.data()
}
})
)
})
這是我的離子代碼:
import { Component, OnInit } from '@angular/core';
import { AngularFireFunctions } from '@angular/fire/functions'
export class SharedModule {}
@Component({
selector: 'app-feed',
templateUrl: './feed.page.html',
styleUrls: ['./feed.page.scss'],
})
export class FeedPage implements OnInit {
posts
sub
constructor(private aff:AngularFireFunctions) {
}
ngOnDestroy() {
this.sub.unsubscribe()
}
ngOnInit() {
const posts = this.aff.httpsCallable('posts')
this.sub = posts({}).subscribe(data =>{
this.posts = data
} )
}
}
如果有人不知道為什么它不起作用,請使用向上按鈕將這個問題推到頂部,也許其他人知道它非常重要,因為我真的需要快速修復這個錯誤
先感謝您
您正在調用可調用的 function :
const posts = this.aff.httpsCallable('posts')
但是您的 function 不是 callalbe 類型。 這是一個HTTP function ,正如您從 function 構建器中的onRequest
中看到的那樣:
export const posts = functions.https.onRequest(async (request, response) => {
如果您想編寫可調用的 function,請使用鏈接文檔中的示例。 您將使用onCall
而不是onRequest
。 請注意,它們具有非常不同的 API。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.