我在我的网站上集成了 stripe api。我使用 stripe、express 和 http-browserify 创建了 bundle.js。并遇到此错误:
bundle.js:50930 Uncaught TypeError: require(...).createServer is not a function at Object.
at Object.require.stripe.../package.json
at s bundle.js:1:262 at /post.html:11:14(anonymous function)
@ bundle.js:50930require.stripe.../package.json
@ bundle.js:51112s
@ bundle.js:1(anonymous function) @ post.html:11
当我点击错误时,它给出错误:
Stripe.DEFAULT_TIMEOUT = require('http').createServer().timeout;
最佳答案
您使用了服务器端 stripe
包,其中 the documentation states :
These are serverside bindings only
If you're looking to install stripe.js, our clientside tokenization library - this is not it. These are serverside node.js bindings only.
您不能在浏览器中使用它们。
客户端库 stripe.js
无法从 NPM 获得,因此您需要以老式的方式将其添加到客户端代码中,方法是:
<script src='https://js.stripe.com/v2/'></script>
关于node.js - bundle.js :50930 Uncaught TypeError: require(. ..).createServer 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40784697/