firebase 连接到fireabse-admin时出错?

jgwigjjp  于 2023-03-31  发布在  其他
关注(0)|答案(1)|浏览(388)

试图连接到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());
2j4z5cfb

2j4z5cfb1#

对于经典的NodeJS Firebase应用程序,使用require进行模块导入:

const admin = require("firebase-admin";
const app = require("../../firebase");

可以使用import关键字为函数设置TypeScript代码。虽然这不是一件容易的事情,但Firebase现在还不能正确地支持TypeScript。

相关问题