【问题标题】:Cannot find name 'require'. ANGULAR 2找不到名称“要求”。角度 2
【发布时间】:2017-10-14 07:06:14
【问题描述】:

我有一个 angular2 应用,我需要在其中使用支付 API。

https://stripe.com/docs/quickstart

在 nodejs 部分的这个代码示例中,他们说要像这样使用它:

// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
var stripe = require("stripe")("sk_test_BQokikJOvBiI2HlWgH4olfQ2");

// Token is created using Stripe.js or Checkout!
// Get the payment token submitted by the form:
var token = request.body.stripeToken; // Using Express

// Charge the user's card:
var charge = stripe.charges.create({
  amount: 1000,
  currency: "usd",
  description: "Example charge",
  source: token,
}, function(err, charge) {
  // asynchronously called
});

我们用 NPM 安装了 requireJS,但是当我们运行它时,我们得到了这个错误:

找不到名称'require'。

  L48:    pagar() {
  L49:      var stripe = require("stripe")("sk_test_ayzCMDmjq2QOIW0s3dTihxNR");

【问题讨论】:

    标签: javascript angular typescript require


    【解决方案1】:

    试试这个:

    import * as stripe from "stripe";
    
    public stripeKey = stripe("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
    

    【讨论】:

    • 看起来解决了 require 问题,但是现在我得到了这个错误: Uncaught TypeError: __webpack_require__(...).createServer is not a function
    猜你喜欢
    • 1970-01-01
    • 2020-05-30
    • 2017-01-29
    • 2017-11-03
    • 2020-12-15
    • 2018-06-28
    • 2016-01-28
    • 2021-03-09
    • 2015-07-07
    相关资源
    最近更新 更多