【问题标题】:FirebaseError:Internal Given While Testing Callable Firebase Cloud Functions with Node ScriptFirebaseError:使用节点脚本测试可调用的 Firebase 云函数时出现内部错误
【发布时间】:2023-02-16 02:11:14
【问题描述】:

环境
火力地堡:9.8.0
节点:v16.14.2

问题
我正在尝试使用函数模拟器使用 Node.js 脚本测试可调用的 Firebase 云函数,但在我的终端中运行脚本时,我不断收到以下错误:

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

即使在使用详细输出运行脚本时,我也没有获得任何更多信息。根据我对 Firebase documentation 的理解,在调用云函数并失败的服务器端存在错误。

Firebase 模拟器工作正常,可以正确响应使用 functions.https.onRequest() 编写的 HTTP 请求。

这是我的功能:

export const helloWorld = functions.https.onCall((data, context) => {

    if (!context.auth) {
        // Throwing an HttpsError so that the client gets the error details.
        throw new functions.https.HttpsError('failed-precondition', 'The function must be called ' +
            'while authenticated.');
      }
    console.log( "hello World" );
    console.log( data );
    console.log( context );
    const responseVal = { retval:"Hello World from callable function." };
    console.log( responseVal )
    return responseVal;
});

这是我的 node.js 脚本(主要基于 Firebase guide for calling functions from your app):

import { initializeApp } from 'firebase/app';
import { getFunctions, httpsCallable, connectFunctionsEmulator } from 'firebase/functions';

const firebaseConfig = {
  apiKey: "...",
  authDomain: "...",
  projectId: "...",
  storageBucket: "...",
  messagingSenderId: "...",
  appId: "...",
  measurementId: "..."
};

const app = initializeApp( firebaseConfig );
const functions = getFunctions( app );
connectFunctionsEmulator( functions, "http://localhost", 5001 );

const helloWorld = httpsCallable( functions, 'helloWorld' );
helloWorld( { hello: "hi" } ) 
  .then( (result) => {
    console.log( "worked" )
    const data = result.data;
    console.log( data.retval );
  })
  .catch( (error) => { 
    console.log( "error", error );
    console.log( "code", error.code );
    console.log( "message", error.message );
    console.log( "details", error.details );
  } )

有没有什么东西会导致我的节点脚本中的函数调用调用 onCall 函数但失败了?

当我尝试在模拟器运行时运行脚本以及在模拟器不运行的情况下运行脚本时,会出现相同的错误。这可能是初始化我的应用程序或将我的应用程序连接到 firebase 模拟器的问题,但我不确定哪里出错了。

谢谢

【问题讨论】:

    标签: javascript node.js firebase


    【解决方案1】:

    指定时区并从 connectFunctionsEmulator() 函数中删除“http://”解决了这个问题。

    
    const app = initializeApp( firebaseConfig );
    const functions = getFunctions( app );
    connectFunctionsEmulator( functions, "http://localhost", 5001 );
    
    

    变成:

    const app = initializeApp( firebaseConfig );
    const functions = getFunctions( app, "us-central1" ); 
    connectFunctionsEmulator( functions, "localhost", 5001 );
    

    【讨论】:

      【解决方案2】:

      更新请我有同样的错误?

      【讨论】:

        猜你喜欢
        • 2020-02-03
        • 1970-01-01
        • 2021-01-20
        • 2018-09-16
        • 2021-06-02
        • 2020-07-07
        • 2020-05-13
        • 1970-01-01
        • 2022-07-25
        相关资源
        最近更新 更多