试图连接到fireabse使用管理员访问和配置是由firebase提供,它是抛出错误,我在问题中添加它似乎库是抛出错误.
firebase.js
import * as admin from "firebase-admin";
const firebaseConfig = {
};
// Initialize Firebase
const app = admin.initializeApp(firebaseConfig);
module.exports = app;
controller.js
import app from '../../firebase';
const db = app.firestore();
const addUser = async (req, res, next) => {
console.log(req.body);
try {
console.log("Adding new user");
const data = req.body;
await db.collection("Users").doc().set(data);
res.status(201).json({ message: "Record saved successfully" });
} catch (error) {
res.status(400).json({ message: error.message });
}
};
modules.exports = { addUser };
错误
ERROR in ./node_modules/firebase-admin/lib/app/firebase-namespace.js 84:65
Module parse failed: Unexpected token (84:65)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| // use the native Promise and then remove this.
| this.Promise = Promise;
> this.INTERNAL = new FirebaseNamespaceInternals(appStore ?? new lifecycle_1.AppStore());
1条答案
按热度按时间2j4z5cfb1#
对于经典的NodeJS Firebase应用程序,使用
require
进行模块导入:可以使用
import
关键字为函数设置TypeScript代码。虽然这不是一件容易的事情,但Firebase现在还不能正确地支持TypeScript。