node.js - Firebase - TypeError:路径必须是字符串。收到未定义
问题描述
我刚开始使用firebase。
我不确定火力基地的来龙去脉,根据我的模糊理解,我已经以这种方式配置了我的应用程序。
在主Index.js文件中,我需要
const path = require('path')
const firebaseConfig = require("./src/config/firebaseConfig.js")
const firebaseDb = require("./src/helperFunctions/firebase_db.js")
在这里,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
}
然后在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)
})
由于这里的大部分代码都是单例的,所以我希望一切顺利,直到收到以下错误
这是 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 中创建一个集合。
解决方案
尝试运行:
npm install firebase-admin@6.4.0
你也可以这样做:(
npm install
npm run build
在函数文件夹内。)
然后firebase deploy
。
为我修好了。
推荐阅读
- sql - SQL Server 中的日期格式
- javascript - 如何将逗号分隔的文本字段转换为单独的行
- java - Java Rest API 在本地主机上工作但不在服务器上
- android-studio - Flutter NoSuchMethodErro:在 null 上调用了方法“tr”。接收方:空
- python - Speech_Recognizer 无法识别我的声音
- go - go-sqlcipher:无法在 Windows 上编译/运行示例
- kubernetes - 如何正确定义部署规范文件
- python - 简化 Nim 游戏的递归算法
- html - Python3 Scrapy 网络爬虫
- android - Proguard 和 Retrofit 的 Kotlinx 序列化异常