当我从解析迁移到 heroku 时,需要模块不工作

Require modul not working when I migrate from parse to heroku

我从 parse 迁移到 heroku,我正在尝试让云代码工作。当云代码文件为空时一切正常,但是当我在 main.js 文件中添加 require Stripe 或 Twilio 行时,我的应用程序中没有任何内容加载。我做错了什么?

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

我今天遇到了问题

我是通过反复试验完成的,这是我记得的

https://www.npmjs.com/package/stripe <- 那是我从

获得云代码的地方
  1. 在你的解析服务器的根目录中通过命令提示符我执行了以下 - npm install stripe
  2. 然后我将条带依赖项添加到 package.json(这个堆栈溢出 post 是丢失的键)"stripe": "~4.9.0",
  3. 云端代码如下

Parse.Cloud.define("charge", 函数(请求, 响应) {

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. 通过您的应用程序使用该云代码并查看它是否在您的条纹仪表板中有效(您必须在仪表板中检查)

所以当我在 package.json 中添加 stripe 作为依赖项时,两个 'breakthroughs' 就出现了,您还可以看到 var stripe = require 在云代码函数中