Skip to content

require("child_process") #107

Closed
Closed

Description

@pksjce

From @cowwoc on January 31, 2015 6:35

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?

Copied from original issue: webpack/webpack#744

Activity

  1. pksjce commented on Sep 7, 2016

    @pksjce
    Author

    From @sokra on January 31, 2015 15:56

    Isn't webpack supposed to be able to provide a web-equivalent?

    Pretty difficult to spawn a process and access the filesystem in the web... So there is no replacement for these modules. Propably means you can't use this module in a browser...

  2. pksjce commented on Sep 7, 2016

    @pksjce
    Author

    From @cowwoc on January 31, 2015 16:7

    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)?

  3. pksjce commented on Sep 7, 2016

    @pksjce
    Author

    From @sokra on January 31, 2015 16:11

    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.

  4. pksjce commented on Sep 7, 2016

    @pksjce
    Author

    From @cowwoc on January 31, 2015 16:54

    Sounds good.

    Is it possible to add this to the official documentation (i.e. "How to handle 3rd-party libraries with unresolved dependencies")? Otherwise, I assume other users will open issues asking the same question for different libraries.

  5. pksjce commented on Sep 7, 2016

    @pksjce
    Author

    From @sheerun on November 26, 2015 13:58

    If you build for electron, you can add child_process to external modules

  6. floatingLomas commented on Sep 13, 2016

    @floatingLomas

    Hey! So, I just wanted to point out that the stripe Node module is only meant to be used server-side, as it requires using a secret key that should never be shared into the wild (on the web).

    If you're looking to capture card details and other things from customers, Stripe.js can help you do that.

  7. SpaceK33z commented on Oct 3, 2016

    @SpaceK33z
    Contributor

    Closing this, what @floatingLomas said is right. You can't use a server side module on the web, and I don't think we can document this any clearer.

  8. added a commit that references this issue on Feb 18, 2017
  9. TomHarker commented on Mar 30, 2017

    @TomHarker

    How are you supposed to know if a node module is browser compatible? And why should webpack care? I'm trying to build for NW.js

  10. fabiooshiro commented on Aug 5, 2017

    @fabiooshiro

    @TomHarker

    I'm trying to build for electron.

    electron workaround

    webpack.config.js

    //...
    externals: {
      child_process: 'child_process'
    }
    //...
    

    index.html

    <script>
    window.child_process = require('child_process');
    </script>

    my_program.js

    const cp = require('child_process'); // its ok but...
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions