Require modul not working when I migrate from parse to heroku

孤街醉人 提交于 2019-12-12 03:49:56

问题


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

"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');

回答1:


i had issues with this today

I did it by trial and error, here is what i remember

https://www.npmjs.com/package/stripe <- thats where i got the cloud code from

  1. in the root directory of your parse-server through command prompt i executed the following - npm install stripe
  2. then i added the stripe dependancy to package.json (this stack overflow post was the missing key) "stripe": "~4.9.0",
  3. the cloud code is as follows

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 
});

});

  1. use that cloud code through your app and see if it works in your stripe dashboard (you must check in the dashboard)

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



来源:https://stackoverflow.com/questions/38890120/require-modul-not-working-when-i-migrate-from-parse-to-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!