automation-stack / node-machine-id

Unique machine (desktop) id (no admin privileges required)
MIT License
582 stars 62 forks source link

Can't resolve 'child_process' #47

Open farhaan008 opened 4 years ago

farhaan008 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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" }