无法对包含条带的函数进行depolly cloud



即使我简单地编写一个helloWorld函数并在其中导入stripe,云函数也不会部署,但只要我删除stripe行,它就会部署。我已经使用npm安装了stripe。我启用了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"}

my--package.json--文件

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

这是函数文件夹中的package.json文件

"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.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函数。我在测试时有以下版本:

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

相关内容

  • 没有找到相关文章

最新更新