Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found : 'child process'

Tags:

I'm developing a ReactJS app with Babel and Webpack. I am using the create-react-app facebook script so it handles the Webpack´s configuration. My problem is that I created a js file and add:

var childProcess = require('child_process');

But when I want to compile the new version i get the following error :

Module not found: 'child_process'.

I don't know what to do with this . I have read that adding custom configurations to the webpack.config.js may be the solution but i am using create react app so I don't have the Webpack configuration. I tried running npm run eject and create my own webpack.config.js but it doesn't work.

I hope somebody could help me.

like image 353
Mati Dastugue Avatar asked Mar 20 '17 04:03

Mati Dastugue


People also ask

Is the module to work with child process?

js allows single-threaded, non-blocking performance but running a single thread in a CPU cannot handle increasing workload hence the child_process module can be used to spawn child processes. The child processes communicate with each other using a built-in messaging system.

What is a child process node?

The node:child_process module provides the ability to spawn subprocesses in a manner that is similar, but not identical, to popen(3) .

What is module pattern node JS?

What is Module Pattern? The module pattern is a special Design pattern in which we use IFFI (Immediately invoked function expression), and we return an object. Inside of that object, we can have functions as well as variables.


1 Answers

You need to configure the correct target inside the webpack configuration: https://webpack.github.io/docs/configuration.html#target

module.exports = {
  entry: './path/to/my/entry/file.js',
  ...
  target: 'node',// we can use node.js modules after adding this configuration
};
like image 107
Tom Van Rompaey Avatar answered Sep 22 '22 10:09

Tom Van Rompaey