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

Next.js调用Firebase可调用函数遇Firebaseerror:not-found问题求助

Firebase Callable函数调用出现not-found错误的排查方案

以下是针对你遇到的Firebaseerror:not-found错误的具体排查和修复步骤:

  • 检查Firebase Functions模拟器的连接配置
    你的firebaseConfig.js中必须添加模拟器连接代码,确保客户端请求指向本地模拟器而非生产环境:

    import { getFunctions, connectFunctionsEmulator } from "firebase/functions";
    
    const functions = getFunctions();
    // 仅在开发环境启用模拟器连接
    if (process.env.NODE_ENV === "development") {
      connectFunctionsEmulator(functions, "localhost", 5001);
    }
    export { functions };
    

    缺少这段配置时,请求会直接发送到Firebase生产环境,而本地模拟器的函数并未部署到生产,因此返回not-found。

  • 确认Functions模拟器已正确加载目标函数
    运行firebase emulators:start --only functions后,查看控制台输出,确认是否包含类似内容:

    functions: Loaded functions from source: addData.
    functions: http function initialized at http://localhost:5001/你的项目ID/us-central1/addData
    

    如果未看到addData被加载,检查函数文件路径是否为默认的functions/index.js,或是函数导出语法是否有误。

  • 修正Callable函数的调用参数
    Firebase Callable函数会自动处理数据的JSON序列化,无需手动调用JSON.stringify,修改调用代码:

    // 错误写法
    // const result = await addData(JSON.stringify(data))
    // 正确写法
    const result = await addData(data)
    

    虽然该问题不会直接导致not-found,但会使函数收到的data为字符串而非预期对象,后续可能引发其他逻辑错误。

  • 验证Firebase项目ID一致性
    确保Next.js配置的Firebase项目ID,与启动模拟器时使用的项目ID完全一致。项目ID不匹配会导致请求端点路径错误,进而触发not-found。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 20:32:15