标签: firebase-cli

如何使用 Firebase-Cli 以编程方式为我的项目创建托管站点?

我需要以编程方式为 CI/CD 创建一个带有 firebase 的登台站点。我可以让多个托管站点按照文档中的描述工作:https : //firebase.google.com/docs/hosting/multisites

但是,此过程需要我转到 firebase Web 应用程序并使用 GUI 创建新的托管站点。

例如运行:

firebase deploy --only hosting:<target>
Run Code Online (Sandbox Code Playgroud)

会导致

“错误:HTTP 错误:404,未找到请求的实体。”

无需在 Web 应用程序中手动添加配置的“.firebaserc 选择的资源名称”。

如何在不涉及 Firebase Web 应用的情况下以编程方式创建托管站点?

firebase google-cloud-platform firebase-cli

7
推荐指数
0
解决办法
277
查看次数

在Cloud Functions Firebase CLI本地模拟器中访问配置变量失败

我正在使用Firebase功能.我通过命令设置了一个环境变量:

firebase functions:config:set my.token="abcde"
Run Code Online (Sandbox Code Playgroud)

我通过命令验证了它:

firebase functions:config:get
Run Code Online (Sandbox Code Playgroud)

谁回报我:

{
  "my": {
    "token": "abcde"
  }
}
Run Code Online (Sandbox Code Playgroud)

在我的index.js中,我尝试通过以下方式获取set token:

const tok = functions.config().my.token
Run Code Online (Sandbox Code Playgroud)

我想测试本文档本地指示的函数,所以我运行命令:

firebase serve --only functions
Run Code Online (Sandbox Code Playgroud)

但它给了我错误:

Error from emulator. FirebaseError: Error occurred while parsing your function triggers.
TypeError: Cannot read property 'token' of undefined
Run Code Online (Sandbox Code Playgroud)

为什么我无法访问我在Firebase的环境变量中设置的令牌?

firebase google-cloud-functions firebase-cli

6
推荐指数
1
解决办法
1086
查看次数

如何从'/ functions'以外的其他目录部署函数?

大卫在他的回购中:

https://github.com/davideast/react-ssr-firebase-hosting

具有firebase功能的文件index.js在主根目录中,而不是/functions目录中.

但是,如果我这样做并将我的index.js文件放到主根,如果我这样做firebase deploy --only functions,请在控制台中说:

i  deploying functions

Error: functions\index.js does not exist, can't deploy Firebase Functions
Run Code Online (Sandbox Code Playgroud)

:他怎么可能让它发挥作用?我怎么能这样做并从其他目录成功部署功能/functions

谢谢

firebase.json

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "function": "ssrapp"
      }
    ]
  },
  "functions": {
     "source": "/"
  }
}
Run Code Online (Sandbox Code Playgroud)

javascript firebase google-cloud-functions firebase-cli

6
推荐指数
2
解决办法
3247
查看次数

Firebase 部署功能 -- 非交互式

我正在集成 CI/CD 以部署我的 firebase 功能。

firebase use PROJECTID --token FIREBASE_TOKEN
firebase deploy --token FIREBASE_TOKEN --non-interactive
Run Code Online (Sandbox Code Playgroud)

现在,每当从 index.js 中删除一个函数时,它都会抛出以下异常。

错误:在您的项目中找到以下函数,但在您的本地源代码中不存在:httpSeeding(us-central1) 正在中止,因为删除无法在非交互模式下进行。要修复,请通过运行手动删除函数:firebase functions:delete httpSeding --region us-central1

在非交互模式下有没有办法在不运行的情况下从控制台中删除已删除的功能 firebase functions:delete httpSeeding

firebase google-cloud-functions google-cloud-firestore firebase-cli

6
推荐指数
2
解决办法
3439
查看次数

firebase部署错误:“eslint不被识别为内部或外部命令、可操作程序或批处理文件”

我想使用 firebase 托管。所以我按照文档中的说明安装 firebase cli...我尝试部署并收到此错误

\n
    \xe2\x86\x90[33m>\xe2\x86\x90[39m firebase deploy\n\n    === Deploying to 'firebase-project-id'...\n\n    i  deploying database, storage, firestore, functions, hosting\n    Running command: npm --prefix "$RESOURCE_DIR" run lint\n\n    > functions@ lint C:\\Users\\somto\\Desktop\\xampp3\\htdocs\\firebaseProjectFolder\\functions\n    > eslint .\n\n    'eslint' is not recognized as an internal or external command,\n    operable program or batch file.\n    npm ERR! code ELIFECYCLE\n    npm ERR! errno 1\n    npm ERR! functions@ lint: `eslint .`\n    npm ERR! Exit status 1\n    npm ERR!\n    npm ERR! Failed at the functions@ lint script.\n    npm ERR! …
Run Code Online (Sandbox Code Playgroud)

windows-7-x64 npm eslint firebase-hosting firebase-cli

6
推荐指数
1
解决办法
2623
查看次数

如何使用 CLI 查看当前登录的 Firebase 帐户?

使用 firebase CLI 如何查看当前登录的 firebase 帐户?我查看了命令列表,但找不到它的命令。这是故意的吗?

firebase-cli

6
推荐指数
1
解决办法
1978
查看次数

Jest/Typescript 测试 Firebase/Firestore Admin SDK 的最佳实践

我正在编写一个应用程序,其后端编写为节点/express 服务器,通过 firebase 功能上的 Admin SDK 运行 firestore 命令。我想知道测试数据库功能的最佳方法是什么。此类函数的示例如下:

export const deleteDocument = async(id: string): Promise<void> => {
    try {
        await firestore.collection("sampleCollection").doc(id).delete();
    } catch (e) {
        throw new Error(`Could not delete ${id}`);
    }
}
Run Code Online (Sandbox Code Playgroud)

然后我想运行一个像这样的单元测试(我知道这里的实际逻辑有点奇怪,但它是即时完成的,并不是问题的重点):

it('should delete a document from the sample collection', async () => {
    //This would already be tested
    const id = await createDocument(...);
    if (id !== undefined) {
      await deleteDocument(id);
      try {
        await getCollective(id);
        expect(true).toBe(false);
      } catch (e) {
        expect(true).toBe(true);
      }
    } else {
      expect(id).toBeDefined();
    } …
Run Code Online (Sandbox Code Playgroud)

firebase typescript jestjs google-cloud-firestore firebase-cli

6
推荐指数
0
解决办法
725
查看次数

如何将 firebase CLI 调试文件(即 ui-debug.log、firebase-debug.log)输出文件夹更改为单独的日志文件夹?

我一直在重构 firebase 的函数文件夹,我想将所有调试输出文件(如 firebase-debug.log 和 ui-debug.log)放在名为“logs”的文件夹中。目前,我的所有日​​志文件都与所有其他文件混合在一起,这很烦人。

我假设firebase.json应该是添加此内容的正确配置文件,但尚未找到此内容。

具体来说,这些是我通过命令运行模拟器时的日志文件:

firebase emulators:start --only functions
Run Code Online (Sandbox Code Playgroud)

我当前的 firebase 函数文件夹结构:

在此输入图像描述

firebase firebase-cli

6
推荐指数
0
解决办法
466
查看次数

“firebase 部署——仅托管”突然失败,并显示“错误:无法列出 &lt;PROJECT&gt; 的功能”

我的 Firebase 托管部署突然开始在我的 Github CI 工作流程和本地计算机中失败。

$ firebase deploy --only hosting

=== Deploying to '<project>'...

i  deploying hosting

Error: Failed to list functions for <project>
Run Code Online (Sandbox Code Playgroud)

该项目没有任何功能,仅托管一个静态站点。谷歌搜索“无法列出功能”结果为空,这似乎不是一个常见问题。我能找到的唯一线索表明某种网络错误。

我已经更新了我的 firebase-tools,注销并再次登录以生成新的 CI 令牌,从我的 Github 工作流程以及从我的机器手动尝试了该过程,所有这些都达到了相同的效果。

我找不到有关此问题的任何信息,除了错误似乎来自 firebase-tools 代码库的这一部分:

https://github.com/firebase/firebase-tools/blob/c0f19a32845135108c75a1050024965cb1e3f52d/src/gcp/cloudfunctions.ts

firebase-hosting firebase-cli

6
推荐指数
2
解决办法
1364
查看次数

Husky 准备脚本未能部署 Firebase 功能

我已经husky在我的 npm 项目中安装了prepare如下脚本

{
  "name": "functions",
  "scripts": {
    "build": "tsc",
    "start": "npm run serve",
    "deploy": "firebase deploy --only functions",
    "prepare": "husky install functions/.husky"
  }
  "dependencies": {
    "firebase-admin": "^11.4.1",
    "firebase-functions": "^4.1.1",
  },
  "devDependencies": {
    "husky": "^8.0.2",
    "typescript": "^4.9.4"
  }
}
Run Code Online (Sandbox Code Playgroud)

husky声明为devDependencies这个 npm 模块仅在本地开发时需要,在运行时应用程序中不需要。

所以当我运行时npm run deploy,我收到以下错误

i  functions: updating Node.js 16 function funName(us-central1)...
Build failed:

> prepare
> husky install functions/.husky

sh: 1: husky: not found
npm ERR! code 127
npm ERR! …
Run Code Online (Sandbox Code Playgroud)

npm firebase google-cloud-functions husky firebase-cli

6
推荐指数
1
解决办法
528
查看次数