Shrads
Shrads

Reputation: 61

Create-react-app Module not found: Error: Cannot resolve module 'child_process'

_Module not found: Error: Cannot resolve module 'child_process' in /project/node_modules/serialport/lib/bindings 

I am facing above error when I build my react application. My application is created using create-react-app and electronjs. I googled for this issue and the most suggested solutions are related to webpack config which I can not directly modify in create-react-app. I tried those solutions like adding 'target: node' and external config etc by ejecting create react app but that also did not work. Before adding serialport package it was working properly now it looks up for the child_process package into serialport libs. So basially in Serialport libs -> linux-list.js they have written const childProcess = require('child_process'); this in the beginning and there it could not get child_process module. I am not sure how to resolve this, Can someone help me out in this?

Upvotes: 1

Views: 374

Answers (1)

Esteban de la Torre
Esteban de la Torre

Reputation: 1

At the root directory where you have your package.json file, you should be able to create a config-overrides.js file. This is where you should be able to specify fallback options.

This is what I have right now in my config-overrides.js file, but for some reason, my project isn't registering the fallback being set to false.

module.exports = {
mode: 'development',
target: 'electron-renderer',
externals: createExternals(), // custom function
entry: '../../common/src/index.js',
plugins: [
    new webpack.ProvidePlugin({
        global: 'globalThis',
    }),
],
resolve: {
    fallback: {
        child_process: false
    }
}

}

Upvotes: 0

Related Questions