node-machine-id icon indicating copy to clipboard operation
node-machine-id copied to clipboard

Strange error on Mac

Open michaelspeed opened this issue 7 years ago • 19 comments

i get this error while using it with electron and react TypeError: (0 , p.exec) is not a function any ideas whats wrong?

michaelspeed avatar Jan 12 '18 17:01 michaelspeed

@michaelspeed Could you provide any details?

automation-stack avatar Jan 16 '18 14:01 automation-stack

using like this - import {machineId, machineIdSync} from 'node-machine-id'; class somthing extends Component { render(){ let id = machineIdSync() <-- Throws error } }

michaelspeed avatar Jan 16 '18 16:01 michaelspeed

@michaelspeed exec is a child_process method, and node modules can only be used in the main process of electron.

*edited for clarity

JM-Mendez avatar Feb 17 '18 13:02 JM-Mendez

Node modules can be used in both the main and render processes of Electron. We're successfully using them in both including native ones. I'm about to use this module in both so I'll let you know if I have trouble.

timfish avatar Mar 09 '18 16:03 timfish

@timfish if you mean node modules like fs, spawn, fork, child_process etc, and not npm modules - they are only available from the main process. You can access them from the renderer by using the ipc or remote modules (which runs the code from the main process). I should have been clearer on that.

JM-Mendez avatar Mar 09 '18 19:03 JM-Mendez

No that's not correct. In the renderer you can directly access any node module including all the built in ones. Give it a try!

timfish avatar Mar 11 '18 14:03 timfish

Here is me just requiring child-process in the Electron renderer dev tools:

image

timfish avatar Mar 11 '18 14:03 timfish

You're absolutely correct, @timfish. I checked an old electron project I worked on and we had node integration set to false. That's why I couldn't access nodejs modules from the renderer process.

JM-Mendez avatar Mar 11 '18 17:03 JM-Mendez

Hi... any solution for mac?

Raghav-Sao avatar Nov 02 '18 08:11 Raghav-Sao

bump

calebswank11 avatar May 07 '19 16:05 calebswank11

Im also facing this problem aswell.

incizzle avatar May 22 '19 13:05 incizzle

Any solution to this yet? Having the same problem on Mac using Electron and React.

davis-jordan avatar Sep 04 '19 02:09 davis-jordan

Same issue here!

patrickmichalina avatar Sep 28 '19 04:09 patrickmichalina

Hello!, Having the same problem in react js app (typescript project).

import { machineIdSync } from 'node-machine-id';

const socket: SocketIOClient.Socket = connect(`${process.env.REACT_APP_SOCKET_IO_SERVER_URL}`, {
        query: {
            deviceId: machineIdSync()
        }
});

lambou avatar Dec 07 '19 04:12 lambou

I don't think it's possible to grab the machine id from the actual react front-end. If you're using Electron try getting the machine id from the main process and passing it through an ipc channel.

greysonn avatar Dec 07 '19 04:12 greysonn

I'm not using electron, but Thanks for replying

lambou avatar Dec 07 '19 04:12 lambou

I'm not using electron, but Thanks for replying

Even in the react app it's not possible for the browser to fetch the machine id. However, an alternative is browser fingerprinting if you don't have a process running in the machine: https://panopticlick.eff.org/static/browser-uniqueness.pdf

greysonn avatar Dec 07 '19 04:12 greysonn

Use remote.require('node-machine-id'); import { ElectronService as NgxService } from 'ngx-electron'; image

danielehrhardt avatar Apr 03 '21 21:04 danielehrhardt

Has anyone found a solution to this?

samp-reston avatar Apr 18 '21 16:04 samp-reston