Zeeshan Shafiq
Zeeshan Shafiq

Reputation: 31

bundle.js:50930 Uncaught TypeError: require(...).createServer is not a function

I have integrated stripe api in my website. I have created bundle.js using stripe, express and http-browserify. and encountered this error:

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

When I click on error it give error on :

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

Upvotes: 3

Views: 943

Answers (2)

num8er
num8er

Reputation: 19372

If You're using this code on clientside:

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



If You're using this code on serverside so... :

The problem is because of: createServer()

from docs:

http.createServer([requestListener])

Added in: v0.1.13

Returns: <http.Server>

Returns a new instance of http.Server.

The requestListener is a function which is automatically added to the 'request' event.

To get at least timeout value You've to pass an empty function to achieve successfully creation of http server.



So dirty fix:

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

Upvotes: 1

robertklep
robertklep

Reputation: 203484

You used the server-side stripe package, of which 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.

You can't use these in a browser.

The client-side library, stripe.js, isn't available from NPM so you need to add it to your client-side code the old-fashioned way, by using:

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

Upvotes: 4

Related Questions