You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

测试Firebase httpsCallable函数时客户端报FirebaseError: internal错误求助

Firebase Functions模拟器调用出现FirebaseError: internal错误

复现步骤

  1. 执行firebase init初始化Firebase配置,选择Functions和Emulators。
  2. 在模拟器选项中选择Functions模拟器和UI模拟器,分别为Functions模拟器分配端口5001,UI模拟器分配端口2000。
  3. 为Functions选择TypeScript,等待依赖下载完成后,将以下代码粘贴到functions/src/index.ts中:
import * as functions from "firebase-functions";

export const helloWorld = functions.https.onCall((data, context) => {
    console.log(data);
    return { success : true };
});
  1. 进入functions/目录执行npm run build构建函数,然后执行firebase emulators: start启动Firebase模拟器。
  2. 新建项目,安装Firebase SDK并通过firebaseConfig初始化SDK,代码如下(src/index.ts):
import { initializeApp } from "firebase/app";
import { connectFunctionsEmulator, getFunctions, httpsCallable } from "firebase/functions";

const firebaseConfig = { /*...firebaseConfig*/ };

const app = initializeApp(firebaseConfig);
const functions = getFunctions(app);
const useEmulator:boolean = true

if(useEmulator) {
    connectFunctionsEmulator(functions, "localhost", 5001);
}

const triggerCallable = httpsCallable(functions, "helloWorld");
const result = await triggerCallable({
    message : "Hello world",
    count: 1
});
console.log(result); // expected : { success : true }
  1. 执行npm run build && node dist/index.js运行编译后的文件,出现以下错误:
node:internal/process/esm_loader:97
    internalBinding('errors').triggerUncaughtException(
                              ^

[FirebaseError: internal] {
  code: 'functions/internal',
  customData: undefined,
  details: undefined
}

模拟器日志中看不到函数初始化的信息,但能看到✔ functions: Loaded functions definitions from source: helloWorld.这条日志。

尝试使用第二代Firebase函数的onCall(),同样出现FirebaseError: internal错误,看起来函数并未正确初始化。

相关资源

firebase.json

{
  "functions": [
    {
      "source": "functions",
      "codebase": "default",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ],
      "predeploy": [
        "npm --prefix \"$RESOURCE_DIR\" run build"
      ]
    }
  ],
  "emulators": {
    "functions": {
      "port": 5001
    },
    "ui": {
      "enabled": true,
      "port": 2000
    },
    "singleProjectMode": true
  }
}

项目结构

.
├── database-debug.log
├── dist
│   ├── index.js
│   └── index.js.map
├── firebase-debug.log
├── firebase.json
├── functions
│   ├── lib
│   │   ├── index.js
│   │   └── index.js.map
│   ├── package.json
│   ├── package-lock.json
│   ├── src
│   │   └── index.ts
│   └── tsconfig.json
├── package.json
├── package-lock.json
├── pubsub-debug.log
├── src
│   └── index.ts
├── tsconfig.json
└── ui-debug.log

客户端tsconfig.json

{
    "compilerOptions": {
        "module": "NodeNext",
        "moduleResolution": "NodeNext",
        "target": "ES2020",
        "sourceMap": true,
        "outDir": "dist"
    },
    "include": ["src/**/*"],
}

已经尝试各种方法仍无法解决,恳请帮忙排查,感谢!

内容的提问来源于stack exchange,提问作者Rocking sam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 00:25:37