简体   繁体   English

部署创建 agora 令牌的 firebase function 时出错

[英]Error while deploying firebase function which creates agora token

I have tried many things to deploy this function, installing and uninstalling node many times and many more tries but it still giving me same error.我已经尝试了很多方法来部署这个 function,安装和卸载节点很多次并且尝试了很多次,但它仍然给我同样的错误。 What I am trying to achieve is using agora-access-token package to generate token using firebase function the code is:我想要实现的是使用 agora-access-token package 使用 firebase function 生成令牌代码是:

const functions = require("firebase-functions");
const {RtcTokenBuilder, RtcRole} = require("agora-access-token");

exports.agoraToken = functions.region("asia-south1").
    https.onCall((data, context)=> {
      const appID = "<myAppID>";
      const appCertificate = "myAppCertificate";
      const uid = data.uid;
      const channelId = data.channelId;
      const role = RtcRole.PUBLISHER;

      const expirationTimeInSeconds = 3600;
      const currentTimestamp = Math.floor(Date.now() / 1000);
      const privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds;
      const token = RtcTokenBuilder.buildTokenWithUid(appID,
          appCertificate, channelId, uid, role, privilegeExpiredTs);
      return token;
    });

And the error is:错误是:

=== Deploying to 'xxxx'... === 部署到“xxxx”...

I deploying functions Running command: npm --prefix "$RESOURCE_DIR" run lint我部署功能运行命令: npm --prefix "$RESOURCE_DIR" run lint

lint eslint.皮棉 eslint。

  • functions: Finished running predeploy script.功能:完成运行预部署脚本。 i functions: ensuring required API cloudfunctions.googleapis.com is enabled... i functions: ensuring required API cloudbuild.googleapis.com is enabled... i functions: ensuring required API artifactregistry.googleapis.com is enabled... i functions: ensuring required API cloudfunctions.googleapis.com is enabled... i functions: ensuring required API cloudbuild.googleapis.com is enabled... i functions: ensuring required API artifactregistry.googleapis.com is enabled...
  • functions: required API artifactregistry.googleapis.com is enabled功能:需要 API artifactregistry.googleapis.com 已启用
  • functions: required API cloudfunctions.googleapis.com is enabled功能:需要 API cloudfunctions.googleapis.com 已启用
  • functions: required API cloudbuild.googleapis.com is enabled i functions: preparing functions directory for uploading... i functions: packaged functions (71.53 KB) for uploading功能:需要 API cloudbuild.googleapis.com 已启用 i 功能:为上传准备功能目录... i 功能:用于上传的打包功能 (71.53 KB)
  • functions: functions folder uploaded successfully i functions: creating Node.js 14 function agoraToken(asia-south1)...函数:函数文件夹上传成功 i 函数:创建 Node.js 14 function agoraToken(asia-south1)...

Functions deploy had errors with the following functions: agoraToken(asia-south1) i functions: cleaning up build files...功能部署有以下功能错误:agoraToken(asia-south1) i 功能:清理构建文件...

Error: There was an error deploying functions错误:部署功能时出错

What I can propose is that you use --debug because it provides information not found in the logs, and it can also fix a problematic deployment.我可以建议您使用--debug ,因为它提供了日志中没有的信息,并且它还可以修复有问题的部署。

Try running the deployment with --debug.尝试使用 --debug 运行部署。 Example: firebase --debug deploy.示例: firebase --debug deploy.

Cloud Function logs can be seen in the Firebase dashboard, the Cloud Logging UI, or the firebase command-line tool. Cloud Function 日志可以在 Firebase 仪表板、Cloud Logging UI 或 firebase 命令行工具中查看。

To view more logs, here is the link to the documentation.要查看更多日志,这里是文档的链接

The problem was that I did not added dependency in package.json file.问题是我没有在 package.json 文件中添加依赖项。 I had to add agora-access-token dependency in package.json in function folder.我必须在 function 文件夹中的 package.json 中添加 agora-access-token 依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM