在 firebase 函数中使用 firebase 工具作为节点模块

Using firebase tools as a node module in firebase function

我正在尝试从 firebase 函数中的 firebase 工具节点模块调用导出方法。

    await firebase_tools.auth.export(tempLocalFile);

但我收到以下错误

FirebaseError: No currently active project.
To run this command, you need to specify a project. You have two options:
- Run this command with [1m--project <alias_or_project_id>[22m.
- Set an active project by running [1mfirebase use --add[22m, then rerun this command.
To list all the Firebase projects to which you have access, run [1mfirebase projects:list[22m.
To learn about active projects for the CLI, visit https://firebase.google.com/docs/cli#project_aliases

有没有办法在nodejs云函数中设置活动项目?

编辑

我正在像这样初始化对象

const firebase_tools = require('firebase-tools');

我并没有完全回答你的问题,但请注意 auth.export 命令在 Cloud Functions 中不起作用。

documentation 中所述(见底部注释):

when used in a limited environment like Cloud Functions, not all firebase-tools commands will work programatically because they require access to a local filesystem.

auth.export命令就是这种情况。另一种方法是使用 Admin SDK 的 listUsers() 方法,如 here.

所述