Cannot use libraries that require 'child_process'
See original GitHub issueIs this a bug report?
No
Can you also reproduce the problem with npm 4.x?
Yes
Environment
-
node -v
: v8.4.0 -
npm -v
: 5.3.0 -
yarn --version
(if you use Yarn): 0.27.5 -
npm ls react-scripts
(if you haven’t ejected): react-scripts@0.9.5 -
Operating system: OSX
-
Browser and version (if relevant): N/A
Steps to Reproduce
- Initialize a create-react-app project
- yarn add thrift
- Require thrift inside any js file
- 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
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top GitHub Comments
This should be resolved as of 1.0.13. Please verify, thanks!
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.