【问题标题】:Cannot depoly cloud functions containing stripe无法分解包含条带的云函数
【发布时间】:2021-09-27 14:39:44
【问题描述】:

即使我只是简单地编写一个 helloWorld 函数并在其中导入条带,云功能也不会部署,但只要我删除条带线,它就会部署。我使用 npm 安装了条带。我启用了 linting 以显示导入时是否有任何错误 - 没有。我检查了 Firebase 控制台以查看是否记录了错误,但代码 3 只有一个错误。这意味着我编写的代码是错误的。但事实是,它只是一个helloworld函数,在开始使用云函数时被注释掉了。我尝试将语言从 javascript 切换到 typescript,并尝试了不同的导入方式,但无济于事。其他人面临同样的问题?顺便说一句,当我上传函数时,由于某种原因,它总是上传到 usCentral1,但我的默认位置是 asiaSouth,这可能是为什么我的函数没有部署集成条带的任何问题吗?

import * as functions from "firebase-functions";
import * as admin from 'firebase-admin';
import Stripe from 'stripe';
const stripe = new Stripe("sk_test_...U7S", {
    apiVersion: '2020-08-27'
})

admin.initializeApp();

// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
export const helloWorld = functions.https.onRequest((request, 
   response) => {
  functions.logger.info("Hello logs!", {structuredData: true});
  console.log(stripe.balance);
  response.send("Hello from Firebase!");
});
{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"Function failed on loading user code. This is 
likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation."},"authenticationInfo":{"principalEmail":"j...1@gmail.com"},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction","resourceName":"projects/testeastylian/locations/us-central1/functions/helloWorld"}

我的 -- package.json -- 文件

{
  "dependencies": {
    "stripe": "^8.163.0"
  },
  "devDependencies": {
    "babel-eslint": "^10.1.0",
    "eslint": "^7.31.0"
  }
}

这是functions文件夹中的package.json文件

"dependencies": {
    "firebase-admin": "^9.8.0",
    "firebase-functions": "^3.14.1"
}

【问题讨论】:

  • 你能分享你的代码和错误截图吗?
  • @Dharmaraj 添加了初始代码和 firebase 日志中产生的错误
  • 您是否启用了 firebase 错误中报告的日志? cloud.google.com/functions/docs/monitoring/logging#viewing_logs
  • 你能分享你的package.json吗?我想确认您使用的 SDK 版本。
  • @Dharmaraj 我们使用相同的依赖项.. 无论如何谢谢。

标签: javascript firebase google-cloud-platform google-cloud-functions stripe-payments


【解决方案1】:

我尝试在 Javascript 和 Typescript 中本地创建初始化 Firebase 项目,并且 SDK 似乎在两者中都有效。您是否正确初始化了项目。

import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
import Stripe from "stripe";
const stripe = new Stripe("sk_test_...U7S", {
  apiVersion: "2020-08-27",
});

admin.initializeApp();

// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
export const helloWorld = functions.https.onRequest((request, response) => {
  functions.logger.info("Hello logs!", {structuredData: true});
  console.log(stripe.balance);
  response.send("Hello from Firebase!");
});

此功能完美运行。我建议尝试在新目录中初始化 Firebase 项目并全新安装所有节点模块。我在下面运行了完全相同的命令:

# create new directory
firebase init functions
# select Typescript and enable ESLint
cd functions
npm i stripe
npm i -D @types/stripe
# paste the code above in index.ts
firebase deploy --only functions

同时确保您使用的是最新版本的 Firebase CLI 和 Firebase Functions。我在测试时有这些版本:

"@types/stripe": "^8.0.417",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1",
"stripe": "^8.163.0"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-26
    • 1970-01-01
    • 2019-05-13
    • 2020-03-04
    • 2019-10-26
    相关资源
    最近更新 更多