automation-stack / node-machine-id

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

Strange error on Mac #31

Open michaelspeed opened 6 years ago

michaelspeed commented 6 years ago

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

automation-stack commented 6 years ago

@michaelspeed Could you provide any details?

michaelspeed commented 6 years ago

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

JM-Mendez commented 6 years ago

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

*edited for clarity

timfish commented 6 years ago

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.

JM-Mendez commented 6 years ago

@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.

timfish commented 6 years ago

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

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

image

JM-Mendez commented 6 years ago

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.

Raghav-Sao commented 5 years ago

Hi... any solution for mac?

calebswank11 commented 5 years ago

bump

incizzle commented 5 years ago

Im also facing this problem aswell.

davis-jordan commented 5 years ago

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

patrickmichalina commented 4 years ago

Same issue here!

lambou commented 4 years ago

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()
        }
});
greysonn commented 4 years ago

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.

lambou commented 4 years ago

I'm not using electron, but Thanks for replying

greysonn commented 4 years ago

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

danielehrhardt commented 3 years ago

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

samp-reston commented 3 years ago

Has anyone found a solution to this?