iT邦幫忙

2

firebase cloud functions typescript多個檔案無法deploy(已解決)

用firebase cloud function寫api
我用的是typescript
我部署從別的ts匯入的function
結果發生找不到的error
是我export寫錯嗎?

檔案結構:
functions
|-lib
|-node_modules
|-src
|-index.ts
|-common.ts

index.ts

import * as functions from 'firebase-functions';
const admin = require('firebase-admin');
const firebase = require('firebase');

admin.initializeApp();

const firebaseConfig = {
};

firebase.initializeApp(firebaseConfig);

import * as _common from './common';

module.exports = {
  _common
};

common.ts

export const log = functions.https.onCall(async (data: any, context: any) => {
    
    // process
    
});

cmd: firebase deploy --only functions:log

error: the following filters were specified but do not match any functions in the project: log

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
dragonH
iT邦超人 5 級 ‧ 2020-02-26 00:27:27
最佳解答

看起來他找不到你的 log

試試看改成這樣

module.exports = {
  log: _common.log
};

module.exports = {
  ..._common
};

我猜的

看更多先前的回應...收起先前的回應...
里歐 iT邦新手 4 級 ‧ 2020-02-27 00:00:26 檢舉

兩種都試過了 還是不行QQ

dragonH iT邦超人 5 級 ‧ 2020-02-27 00:08:09 檢舉

那乖乖就用 ES6 的 export

里歐 iT邦新手 4 級 ‧ 2020-02-27 21:53:18 檢舉

我找到問題了!
由於我在functions裡的ts檔有引用functions外部的檔案
所以build完在lib裡會產生不同資料夾分層的js
所以導致他找不到

dragonH iT邦超人 5 級 ‧ 2020-02-27 21:59:31 檢舉

所以 index.ts export 的部分不需要調整嗎

里歐 iT邦新手 4 級 ‧ 2020-02-27 22:02:16 檢舉

我是改成直接最簡單

export * from './common';
export * from './auth';

連import也不用

dragonH iT邦超人 5 級 ‧ 2020-02-27 22:38:46 檢舉

喔喔 了解 /images/emoticon/emoticon12.gif

我要發表回答

立即登入回答