当我从解析迁移到heroku时,要求模块无法正常工作 [英] Require modul not working when I migrate from parse to heroku
问题描述
我从解析迁移到了heroku,并且试图使云代码正常工作.当云代码文件为空白时,一切工作正常,但是当我在main.js文件中添加require Stripe或Twilio行时,我的应用程序中不会加载任何内容.我在做什么错了?
I migrated from parse to heroku and I am trying to get cloud code to work. Everything works fine when the cloud code file is blank, but when I add the require Stripe or Twilio lines in the main.js file, nothing in my app loads. What am I doing wrong?
package.json
package.json
"dependencies": {
"express": "~4.11.x",
"kerberos": "~0.0.x",
"parse": "~1.8.0",
"parse-server": "~2.2.12",
"stripe": "~4.9.0",
"twilio": "~2.9.2"
}
main.js
var Stripe = require('stripe');
Stripe.initialize('sk_test_xxxxxxx');
推荐答案
我今天对此有疑问
我是通过反复试验做到的,这是我记得的
I did it by trial and error, here is what i remember
https://www.npmjs.com/package/stripe <-那是我从那里获得了云代码
https://www.npmjs.com/package/stripe <- thats where i got the cloud code from
-
通过命令提示符
- 在解析服务器的根目录中,我执行了以下命令- npm install stripe
- 然后我将数据条依赖性添加到package.json(此堆栈溢出后的内容是缺少的键)"stripe":〜4.9.0",
- 云代码如下
- in the root directory of your parse-server through command prompt i executed the following - npm install stripe
- then i added the stripe dependancy to package.json (this stack overflow post was the missing key) "stripe": "~4.9.0",
- the cloud code is as follows
Parse.Cloud.define("charge",function(request,response){
Parse.Cloud.define("charge", function(request, response) {
var stripe = require('stripe')('sk_test_****');
stripe.customers.create({
email: theEmailAddress
}).then(function(customer) {
return stripe.charges.create({
amount: yourAmount,
currency: yourCurrency,
card: yourToken,
description: yourDescription
});
}).then(function(charge) {
// New charge created on a new customer
}).catch(function(err) {
// Deal with an error
});
});
- 通过您的应用程序使用该云代码,并查看它是否在条纹仪表板中正常工作(您必须在仪表板中检入)
所以当我在package.json中添加数据条作为依赖项时出现了两个突破",您还可以看到var stripe = require
在云代码功能内部
so the two 'breakthroughs' came when i added stripe as a dependancy in package.json and also can you see that var stripe = require
is inside the the cloud code function
这篇关于当我从解析迁移到heroku时,要求模块无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!