require(“child_process”)

I was attempting to package stripe.js when I ran across this line: https://github.com/stripe/stripe-node/blob/master/lib/stripe.js#L24

ERROR in ./~/stripe/lib/stripe.js
Module not found: Error: Cannot resolve module 'child_process' in ~\node_modules\stripe\lib
 @ ./~/stripe/lib/stripe.js 24:11-35

ERROR in ./~/stripe/lib/StripeResource.js
Module not found: Error: Cannot resolve module 'fs' in ~\node_modules\stripe\lib
 @ ./~/stripe/lib/StripeResource.js 14:31-44

If I understand correctly, these are two built-in modules that ship with node.js. Isn’t webpack supposed to be able to provide a web-equivalent?

What do you recommend I do in this case?

Author: Fantashit

5 thoughts on “require(“child_process”)

  1. What is the proper course of action?

    I read elsewhere that I can do this:

    node:
    {
        "child_process": "empty"
    }
    

    but is there a better approach (keeping in mind that I can’t modify the 3rd-party library)?

  2. yes you can do that and hope that the module doesn’t use any of the methods from this modules.

    The proper course is the ask the module author to make the module browser compatible. The author can add browser: { fs: false, child_process: false } to the package.json to tell webpack that it’s ok for the module to get an empty object for these modules.

Comments are closed.