【问题标题】:bundle.js:50930 Uncaught TypeError: require(...).createServer is not a functionbundle.js:50930 Uncaught TypeError: require(...).createServer is not a function
【发布时间】:2016-11-24 11:01:13
【问题描述】:

我在我的网站中集成了条带 API。我使用 stripe、express 和 http-browserify 创建了 bundle.js。并遇到了这个错误:

bundle.js:50930 Uncaught TypeError: require(...).createServer is not a 功能 在对象处。

在 Object.require.stripe.../package.json

在 bundle.js:1:262 在/post.html:11:14(匿名函数)

@bundle.js:50930require.stripe.../package.json

@bundle.js:51112s

@bundle.js:1(匿名函数)@post.html:11

当我点击错误时,它会给出错误:

Stripe.DEFAULT_TIMEOUT = require('http').createServer().timeout;

【问题讨论】:

  • 你没有得到读取超时值的地方,你做了那个把戏? (:

标签: node.js stripe-payments browserify


【解决方案1】:

你使用了服务端的stripe包,其中the documentation states

这些只是服务器端绑定

如果您正在寻找安装我们的客户端标记化库 stripe.js - 这不是它。这些只是服务器端 node.js 绑定。

您不能在浏览器中使用这些。

客户端库 stripe.js 不能从 NPM 获得,因此您需要使用老式方式将其添加到客户端代码中:

<script src='https://js.stripe.com/v2/'></script>

【讨论】:

    【解决方案2】:

    如果您在客户端使用此代码:

    You cannot, at least You've to provide this `timeout` param from backend.
    or just hardcode it and etc.
    



    如果您在服务器端使用此代码,那么...:

    问题是因为:createServer()

    来自docs

    http.createServer([requestListener])

    添加于:v0.1.13

    Returns: <http.Server>
    

    返回一个新的 http.Server 实例。

    requestListener 是一个自动添加到 “请求”事件。

    要获得至少超时值你必须传递一个空函数才能成功创建http服务器。



    如此肮脏的修复:

    Stripe.DEFAULT_TIMEOUT = require('http').createServer(function(){}).timeout;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-25
      • 2016-01-05
      • 2014-08-15
      • 2021-12-16
      • 2018-04-20
      • 2017-04-13
      • 2015-01-14
      相关资源
      最近更新 更多