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

Can't resolve 'child_process' #47

Open
farhaan008 opened this issue Sep 15, 2020 · 2 comments
Open

Can't resolve 'child_process' #47

farhaan008 opened this issue Sep 15, 2020 · 2 comments

Comments

@farhaan008
Copy link

On importing import {machineId, machineIdSync} from 'node-machine-id' in app component then getting this error. Any work around for the same.
ERROR in ./node_modules/node-machine-id/dist/index.js
Module not found: Error: Can't resolve 'child_process' in 'C:\Users\farhan\Desktop\ Farhan\Projects\BFMC\BFMClient\node_modules\node-machine-id\dist'

@MarkusSvensson
Copy link

I had the same problem, I think. You are probably using machineIdSync in the Electron renderer process? child_process is a node module and can only be accessed from the main process.

Try a request from the renderer process:

this.userId = this.electronService.ipcRenderer.sendSync('UUID_REQUEST')

And in the main process:

ipcMain.on('UUID_REQUEST', async (event, args) => {
    event.returnValue = machineIdSync();
});

@MarkusSvensson
Copy link

MarkusSvensson commented Nov 1, 2020

Faced with the same problem I did some research. With inspiration from https://stackoverflow.com/questions/54459442/module-not-found-error-cant-resolve-child-process-how-to-fix I solved it for the rendering process by adding following config for webpack.config.js. After this change I get a machine id when running a build electron app, when running "serve" it fails with an exception at execution but that is ok for me.
node: { child_process: "empty" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants