6

這個當函數是Node.js的index.js文件的標題:admin.firestore不嘗試使用谷歌雲功能與node.js的

const functions = require('firebase-functions'); 
const admin = require('firebase-admin'); 
admin.initializeApp(functions.config().firebase); 
var db = admin.firestore(); 

這是Node.js的功能聽公司的FireStore變化:

exports.myFoo = functions.firestore 
    .document('foo/{bar}') 
    .onWrite(event => { 
    // do stuff 
} 

這是的package.json文件:

"dependencies": { 
    "firebase-admin": "^5-.4.2", 
    "firebase-functions": "^0.7.1", 
    "firestore": "^1.1.6" 
    }, 

當我嘗試做一個 「火力部署」命令這是我得到的錯誤:

Error: Error occurred while parsing your function triggers.
TypeError: admin.firestore is not a function

askFirebase

+0

也許你沒有最新版本的SDK。通過在項目的函數目錄中運行'npm install firebase-functions @ latest --save',按照[文檔](https://firebase.google.com/docs/functions/get-started#set_up_and_initialize_functions_sdk)中的描述獲取它。 –

+0

我不認爲你需要依賴關係中的firestore?我有一個工作的firestore/firebase函數代碼片段,只有兩個依賴「firebase-admin」:「^ 5.4.1」和「firebase-functions」:「^ 0.7.0」' – DauleDK

+0

@BobSnyder我跑了'npm install firebase-functions @ latest --save'和'npm install -g firebase-tools'然後再次嘗試'firebase deploy',但仍然出現相同的錯誤消息。我有firebase版本3.13.1和npm版本3.10.10。 –

回答

9

我能夠重現錯誤和蠻力力的解決方案。我對npm瞭解不多,不能提供此解決方案工作原因的完整說明。

我原來package.json包含:

"dependencies": { 
    ... 
    "firebase-admin": "^4.2.1", 
    "firebase-functions": "^0.7.1", 
    ... 
    }, 

由於recommended in the documentation,我跑在功能文件夾這兩個命令:

npm install -g firebase-tools 
npm install [email protected] --save 

我也試過:

npm install --save firebase-admin 
npm upgrade 

我多次獲得這些錯誤消息:

+-- UNMET PEER DEPENDENCY [email protected] 
npm WARN [email protected] requires a peer of [email protected]~5.4.2 but none was installed. 

我想firebase-admin需要更新,但不能實現。所以,我編輯的依賴文件刪除這一行:

"firebase-admin": "^4.2.1" 

然後又跑npm install --save firebase-admin。與此同時,package.json包含版本"firebase-admin": "^5.4.2"var db = admin.firestore();編譯沒有錯誤。