2017-10-18 59 views
3

運行準系統節點文件時加載「protobuf.js」:無法獲取文檔的FireStore

const firebase = require("firebase"); 
const http = require('http') 

require("firebase/firestore"); 

firebase.initializeApp({ 
    apiKey: '...', 
    authDomain: '...', 
    databaseURL: '...', 
    serviceAccount: '...', 
    projectId: '...' 
}); 

var db = firebase.firestore(); 
var userRef = db.collection('...').doc('...'); 

結果在下面的終端規則

Firestore (4.5.2) 2017-10-18T19:16:47.719Z: INTERNAL UNHANDLED ERROR: Error: Failed to fetch file at /.../project/node_modules/protobufjs/dist/protobuf.js:5164:30 at ReadFileContext.callback (/.../p/node_modules/protobufjs/dist/protobuf.js:358:29) at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:420:13) (node:43981) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to fetch file (node:43981) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

但我查了node_modules文件夾,它的存在。我也嘗試重新安裝它,其他人似乎沒有與當前版本的protobuf.js有問題。

+0

我今天有同樣的問題。添加下面的答案以顯示類似的方法並記錄輸出和配置。 – Krispy

回答

2

類似的問題:

const firebase = require('firebase'); 
require("firebase/firestore"); 
const config = { 
    apiKey: "-redacted-", 
    authDomain: "-redacted-", 
    databaseURL: "-redacted-", 
    projectId: "-redacted-", 
    storageBucket: "-redacted-", 
    messagingSenderId: "-redacted-" 
}; 
firebase.initializeApp(config); 
let db = firebase.firestore(); 
let ref=db.collection('example').doc('test'); 
ref.set({test:true}); 

錯誤控制檯(節點v6.11.4):

Firestore (4.5.2) 2017-10-18T19:48:00.297Z: INTERNAL UNHANDLED ERROR: Error: Failed to fetch file 
at Error (native) 
at /Users/krispy.uccello/Development/devrel/constellation/functions/node_modules/protobufjs/dist/protobuf.js:5164:30 
at ReadFileContext.callback (/Users/krispy.uccello/Development/devrel/constellation/functions/node_modules/protobufjs/dist/protobuf.js:358:29) 
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:367:13) 

(節點:71564)UnhandledPromiseRejectionWarning:未處理的承諾拒絕(拒絕ID:1):錯誤:無法抓取文件

的數據庫規則:

service cloud.firestore { 
    match /databases/{database}/documents { 
    match /{document=**} { 
     allow read, write: if true; 
    } 
    } 
} 

更新: 此問題似乎只與寫入有關。我能夠毫無問題地從Firestore讀取數據。

更新#2: 我寫了一個firebase函數來處理寫操作,它的工作。這個問題可能與客戶端安裝的protobuf js的發佈版本有關。不確定在Firebase端使用了哪些版本,但似乎可行。查看通過firebase https觸發器調用的以下函數 - 它的工作原理和數據顯示在firestore數據庫中。

function writeWorkerProfile(id, data, res) { 
    let ref = 
    db.collection('scratch').doc('v1').collection('workers').doc(`${id}`); 
    ref.set(data) 
    .then(function() { 
    console.log("Document successfully written!"); 
    res.status(200).send({ok:true}) 
    }) 
    .catch(function(error) { 
     console.error("Error writing document: ", error); 
     res.status(500).send('Error occurred: Could not write data'); 
    }); 
} 
+0

你用什麼代碼閱讀?您是如何啓動Firebase https觸發器的?謝謝! (對此爲新的) – user61871

+0

請參閱以下要點 https://gist.github.com/kuccello/d68f671ad396b8741bcdd47a7218044b https://gist.github.com/kuccello/4d367cc011aa941a456f60a01826a02f – Krispy

+0

以下是讀取功能: https:// gist .github.com/kuccello/0ae3314bdf4d14128ee41e05cb4b5507 – Krispy

相關問題