Skip to content

Cannot use libraries that require 'child_process' #3032

Closed
@ghost

Description

Is this a bug report?

No

Can you also reproduce the problem with npm 4.x?

Yes

Environment

  1. node -v: v8.4.0

  2. npm -v: 5.3.0

  3. yarn --version (if you use Yarn): 0.27.5

  4. npm ls react-scripts (if you haven’t ejected): react-scripts@0.9.5

  5. Operating system: OSX

  6. Browser and version (if relevant): N/A

Steps to Reproduce

  1. Initialize a create-react-app project
  2. yarn add thrift
  3. Require thrift inside any js file
  4. yarn start

Expected Behavior

The dev server will work as expected.

Actual Behavior

The dev server complains about:

Module not found: Error: Cannot resolve module 'child_process'

Details

I am including the thrift library just for serializing/deserializing objects client side, and due to somewhere in the library where it requires 'child_process', it fails to load the dev server.

If I go to:
/node_modules/react-scripts/config/webpack.config.*.js

and append child_process: 'empty' to

  // Some libraries import Node modules but don't use them in the browser.
  // Tell Webpack to provide empty mocks for them so importing them works.
  node: {
    fs: 'empty',
    net: 'empty',
    tls: 'empty'
  }

Then I can successfully load the server. Would it be an unreasonable pull request to add this? Thrift does use this when making connections, but since connections aren't being done in this use case, I figured stubbing child_process like fs makes the most sense.

I can do this manually, but everytime there's an update or a new clone, it's back to it's broken state.

Thanks,
Anthony

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions