Open michaelspeed opened 6 years ago
@michaelspeed Could you provide any details?
using like this -
import {machineId, machineIdSync} from 'node-machine-id'; class somthing extends Component { render(){ let id = machineIdSync() <-- Throws error } }
@michaelspeed exec is a child_process method, and node modules can only be used in the main process of electron.
*edited for clarity
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 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.
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!
Here is me just requiring child-process
in the Electron renderer dev tools:
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.
Hi... any solution for mac?
bump
Im also facing this problem aswell.
Any solution to this yet? Having the same problem on Mac using Electron and React.
Same issue here!
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()
}
});
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.
I'm not using electron, but Thanks for replying
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
Use
remote.require('node-machine-id');
import { ElectronService as NgxService } from 'ngx-electron';
Has anyone found a solution to this?
i get this error while using it with electron and react
TypeError: (0 , p.exec) is not a function
any ideas whats wrong?