gpt4 book ai didi

javascript - Fire Base 云功能在 Node.js 文件中不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 03:14:12 24 4
gpt4 key购买 nike

当我在 CMD 中运行 node index.js 命令时,我正在运行此代码,它运行良好,但当我将其用于 firebase 云函数时,相同的代码没有运行。我可能是错的,但找不到问题,我已经搜索这个问题 1 周了。此代码正在运行

stripe.customers.create({
email: 'testemail@gmail.com',
}).then((customer) => {
return null;
// functions.firestore.document('data/{card}/payment/{tokenid}').set(customer.id)
});

但这不起作用

exports.StripeSource =functions.firestore.document('data/{card}/tokens/{tokenid}').onCreate((user) => {
return stripe.customers.create({
email: 'testemail@gmail.com',
}).then((customer) => {
return null;
// functions.firestore.document('data/{card}/payment/{tokenid}').set(customer.id)
});
});

Fire Base 功能日志为

 {"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":
{"code":3,"message":"INVALID_ARGUMENT"},"authenticationInfo":
{"principalEmail":"name.dev@domain.tv"},"requestMetadata":{"requestAttributes":
{},"destinationAttributes":
{}},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.fun
ctions.v1.CloudFunctionsService.UpdateFunction","resourceName":"projects/payment
bystripe/locations/us-central1/functions/StripeSource"}

此处为 Visual Studio 代码终端报告

C:\Users\Waqas\AndroidStudioProjects\flutter_stripe_payment1\android\functions\functions>firebase deploy --only functions

=== Deploying to 'paymentbystripe'...

i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint C:\Users\Waqas\AndroidStudioProjects\flutter_stripe_payment1\android\functions\functions
> eslint .

+ functions: Finished running predeploy script.
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (37.28 KB) for uploading
+ functions: functions folder uploaded successfully
i functions: updating Node.js 8 function StripeSource(us-central1)...
! functions[StripeSource(us-central1)]: Deployment error.
Function failed on loading user code. Error message: Code in file index.js can't be loaded.
Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'stripe'
at Function.Module._resolveFilename (module.js:548:15)
at Function.Module._load (module.js:475:25)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/srv/index.js:5:16)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)


Functions deploy had errors with the following functions:
StripeSource


To try redeploying those functions, run:
firebase deploy --only functions:StripeSource


To continue deploying other features (such as database), run:
firebase deploy --except functions

Error: Functions did not deploy properly.

C:\Users\Waqas\AndroidStudioProjects\flutter_stripe_payment1\android\functions\functions>

最佳答案

您没有安装 stripe。我建议您查看 package.json 中的依赖项并添加 "stripe":"^6.20.0"。任何新版本都可以解决这个问题。

最后运行 Firebase 部署。我希望这会有所帮助。

关于javascript - Fire Base 云功能在 Node.js 文件中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59143622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com