question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot use libraries that require 'child_process'

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Timercommented, Sep 4, 2017

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

1reaction
miraagecommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

nodejs child_process package fails to work for python ...
The issue is, once I import either of two necessary libraries for my python script (pandas and sklearn), the script halts and neither...
Read more >
Child process | Node.js v19.3.0 Documentation
On Windows, however, .bat and .cmd files are not executable on their own without a terminal, and therefore cannot be launched using child_process....
Read more >
Node.js Child Processes: Everything you need to know
The child_process module enables us to access Operating System functionalities by running any system command inside a, well, child process. We ...
Read more >
Getting to know Node's child_process module
Accordingly, I've decided to write an article about Node's child_process module — a utility module which provides you with functions that can ...
Read more >
Child Process in Nodejs
... we can't block the main thread for these kinds of calculations. ... kinds of computations, we need to use the inbuilt library...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found