【发布时间】: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