简体   繁体   English

部署云时出错 function Firebase/Stripe

[英]Error when I deploy cloud function Firebase/Stripe

this is the first time I try to deploy cloud function in Firebase, usually I use Direbase emulator, but in this case, using Stripe, I am having problems with Cors. When I run the command: firebase deploy --only functions , I have no compilation errors, but it tells me that there were errors during the release.这是我第一次尝试在 Firebase 中部署云 function,通常我使用 Direbase 模拟器,但在这种情况下,使用 Stripe,我遇到了 Cors 的问题。当我运行命令时: firebase deploy --only functions ,我有没有编译错误,但它告诉我在发布期间有错误。 Seeing from the Firebase console, I notice that in the logs, it says:从 Firebase 控制台看,我注意到在日志中,它说:

"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"Function failed on loading user code. "@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"函数加载用户代码失败。

This is my cloud function, I don't understand the error what is:这是我的云function,我不明白错误是什么:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const stripe = require("stripe")(functions.config().stripe.secret_key);
admin.initializeApp(functions.config().firebase);

export const createCheckoutSessionGreen = functions.region("europe-west6")
    .https.onCall(
        async (data: any, context: any) => {
          const session = await stripe.checkout.sessions.create({
            payment_method_types: ["card"],
            mode: "payment",
            success_url: "http://localhost:8100/tabs/types/song",
            cancel_url: "http://localhost:8100/tabs/types/song",
            line_items: [
              {
                price_data: {
                  currency: "eur",
                  product_data: {
                    name: data,
                  },
                  unit_amount: 1.99 * 100,
                },
                quantity: 1,
              },
            ],
          });
          return session.id;
        }
    );

You need to use Typescript with Cloud Function if you want to use the ES6 syntax.如果要使用ES6语法,则需要使用 Typescript 和 Cloud Function。 It seems you are using Javascript so try refactoring the code using exports instead of export const .看来您正在使用 Javascript 所以尝试使用exports而不是export const重构代码。 Also you don't need to pass any parameters to initializeApp() since you are deploying to Cloud Functions which will then use Application Default Credentials :此外,您不需要将任何参数传递给initializeApp() ,因为您正在部署到 Cloud Functions,后者将使用应用程序默认凭证

admin.initializeApp();

exports.createCheckoutSessionGreen = functions.region("europe-west6").https.onCall(...)

暂无
暂无

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

相关问题 Firebase 云 function 部署错误 - Firebase cloud function deploy error 导入 @google-cloud/storage 部署时 p-limit lib 出错 firebase function - Error in p-limit lib when importing @google-cloud/storage to deploy firebase function Firebase 部署错误:将单独的项目与 Stripe“使用 Stripe 运行付款”扩展一起使用时,“不支持更改机密” - Firebase Deploy Error: 'Changing secrets is not supported' when using separate projects with Stripe 'Run Payments with Stripe' extension 无法部署到 firebase 云 function - Can´t deploy to firebase cloud function 无法在 flutter 中部署 Firebase 云 Function - Cannot deploy Firebase Cloud Function in flutter Firebase 云函数部署错误 - 超出配额 - Firebase Cloud Functions Deploy Error - Quota Exceeded 我正在尝试将我的简单 typescript 应用程序部署到 firebase 云功能。 但我有这个错误 - I'm trying to deploy my simple typescript app to firebase cloud functions. But I have got this error 当我尝试部署 firebase function (基本你好世界)时,我收到此错误:FetchError:无法获取本地颁发者证书 - When I try to deploy firebase function (basic hello world), i get this error :FetchError: unable to get local issuer certificate Firebase 云 function cors 即使添加 cors 中间件也会出错 - Firebase cloud function cors error even when adding cors middleware 我无法部署 firebase 云功能:无法从源加载 function 定义,D:\ 中没有定义“导出”主要内容 - I cannot deploy firebase cloud functions: Failed to load function definition from source, No "exports" main defined in D:\
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM