Skip to content

require("child_process") #744

Closed
Closed

Description

@cowwoc

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?

Activity

  1. sokra commented on Jan 31, 2015

    @sokra
    Member

    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. cowwoc commented on Jan 31, 2015

    @cowwoc
    Author

    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. sokra commented on Jan 31, 2015

    @sokra
    Member

    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. cowwoc commented on Jan 31, 2015

    @cowwoc
    Author

    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. sheerun commented on Nov 26, 2015

    @sheerun

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

  6. pksjce commented on Sep 7, 2016

    @pksjce

    This issue was moved to webpack/webpack.js.org#107

  7. TomHarker commented on Mar 30, 2017

    @TomHarker

    How are you supposed to know if a module is browser compatible? I'm trying to build for NW.js

  8. bebraw commented on Mar 31, 2017

    @bebraw
    Contributor

    @TomHarker Can you open a Stack Overflow question for that and link there? My understanding is that you can't tell that without running a file (not enough metadata) in an environment.

  9. TomHarker commented on Mar 31, 2017

    @TomHarker

    http://stackoverflow.com/questions/43128454/importing-and-using-node-modules

    Here is the stackoverflow question. It just seems odd that people are happy to use node to build and manage a project with node at a system level, then in the same breath expect to use it in the web project they are making.

  10. bebraw commented on Mar 31, 2017

    @bebraw
    Contributor

    @TomHarker Yeah. I think some of this has to do with history. npm started backend-only and the frontend portions were sort of bolted in so people didn't give any conscious thought to this on specification level. I guess in ideal world you could tell the difference based on package.json metadata alone but that's not likely to happen. 😄

  11. cesargdm commented on Jul 15, 2017

    @cesargdm

    @sheerun how do you define that?

  12. sheerun commented on Jul 16, 2017

    @sheerun

    I don't remember now, but probably "externals" field for webpack 1, and following for webpack 2: https://webpack.js.org/configuration/externals/

  13. wagenaartje commented on Aug 5, 2017

    @wagenaartje

    Add

      externals: [
        'child_process'
      ]
  14. kdenaeem commented on Apr 3, 2018

    @kdenaeem

    @wagenaartje is that code to be added in the javascript of the website?
    Is it supposed to added in the methods or somewhere like that?

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

    No labels
    No 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