Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use libraries that require 'child_process' #3032

Closed
ghost opened this issue Aug 30, 2017 · 5 comments
Closed

Cannot use libraries that require 'child_process' #3032

ghost opened this issue Aug 30, 2017 · 5 comments

Comments

@ghost
Copy link

ghost commented Aug 30, 2017

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

@ghost ghost changed the title Cannot use libraries that Cannot use libraries that require 'child_process' Aug 30, 2017
@gaearon
Copy link
Contributor

gaearon commented Aug 30, 2017

I wouldn't mind that. PR?

@ghost
Copy link
Author

ghost commented Aug 30, 2017

Thanks for the quick response, coming right up.

@ghost
Copy link
Author

ghost commented Aug 30, 2017

Done, #3033

@miraage
Copy link

miraage commented Sep 4, 2017

https://www.npmjs.com/package/thrift package is only supports NodeJS, while you're trying to use it in browser environment. child-process is a built-in NodeJS module, that's why you can't use it.

@Timer
Copy link
Contributor

Timer commented Sep 4, 2017

This should be resolved as of 1.0.13. Please verify, thanks!

@Timer Timer closed this as completed Sep 4, 2017
@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants