Firebase - 类型错误:路径必须是字符串。收到未定义

iRo*_*tia 5 node.js express firebase

我刚刚开始使用firebase。

我不确定firebase的来龙去脉,根据我模糊的理解,我已经这样配置了我的应用程序。

在主Index.js文件中,我需要

const path = require('path')
const firebaseConfig = require("./src/config/firebaseConfig.js")
const firebaseDb = require("./src/helperFunctions/firebase_db.js")
Run Code Online (Sandbox Code Playgroud)

在这里,firebaseConfig 是我配置我的 firebase 的地方

const firebaseConfigJSON = require("./functions-config.json")
const admin = require("firebase-admin");


admin.initializeApp({
    credential: admin.credential.cert(firebaseConfigJSON),
    databaseURL: "https://functions-firebase-43a59.firebaseio.com"
})

const db =  admin.firestore()
db.settings({ timestampsInSnapshots: true });

 module.exports = {
    db
 }
Run Code Online (Sandbox Code Playgroud)

然后使用这个导入的数据库 firebaseDb

//All the operations at firebase store would be done from here 
const firebaseDb = require("./../config/firebaseConfig.js")

    firebaseDb.db.collection('users').add({
        name: "Rohit Bhatia",
        age: "24"
    })
    .then((response) => {
        console.log("this is response", response)
    })
    .catch((err) => {
        console.log("This is error in firebase", err)
    })
Run Code Online (Sandbox Code Playgroud)

由于这里的大部分代码都是单例的,我期待一切顺利,直到我收到以下错误

这是 firebase TypeError 中的错误:路径必须是字符串。收到未定义

在 assertPath (path.js:28:11)

在 Object.join (path.js:1236:7)

在 getPath (/Users/anilbhatia/Desktop/google-functions/functions/node_modules/dir-glob/index.js:6:41)

在 globs.concat.map.x (/Users/anilbhatia/Desktop/google-functions/functions/node_modules/dir-glob/index.js:47:59)

在 Array.map()

在 module.exports.sync (/Users/anilbhatia/Desktop/google-functions/functions/node_modules/dir-glob/index.js:47:33)

在 globDirs (/Users/anilbhatia/Desktop/google-functions/functions/node_modules/globby/index.js:58:9)

在 getPattern (/Users/anilbhatia/Desktop/google-functions/functions/node_modules/globby/index.js:61:64)

在 globTasks.reduce (/Users/anilbhatia/Desktop/google-functions/functions/node_modules/globby/index.js:107:19) 在 Array.reduce ()

有人可以帮我弄清楚我做错了什么吗?或者也许我真的得到了火力?

我最初的目标是在从 api 路由放入数据之前,通过我的 express 应用程序在我的 firebase 中创建一个集合。

Eys*_*Bye 2

我们可以dir-glob通过添加以下内容将其恢复到 2.0.0:

"dir-glob": "2.0.0",
"globby": "8.0.0",
Run Code Online (Sandbox Code Playgroud)

在 package.json 中dependencies

您可以通过以下方式执行此操作:

npm install dir-glob@2.0.0 --save
npm install globby@8.0.0 --save
Run Code Online (Sandbox Code Playgroud)

然后我们删除node_modules并运行:npm install并部署到 Firebase