wilix-team / iohook

Node.js global keyboard and mouse listener.
https://wilix-team.github.io/iohook
MIT License
1.16k stars 286 forks source link

Uncaught Exception: Error: Cannot find module '/home/logicrays/Documents/practice project/Learn electronjs/web-tracker-electron-app/node_modules/iohook/builds/electron-v113-linux-x64/build/Release/iohook.node' #431

Open vimalAtLR opened 1 year ago

vimalAtLR commented 1 year ago

Uncaught Exception: Error: Cannot find module '/home/logicrays/Documents/practice project/Learn electronjs/web-tracker-electron-app/node_modules/iohook/builds/electron-v113-linux-x64/build/Release/iohook.node' Require stack:

const { app, BrowserWindow, globalShortcut } = require("electron"); const windowStateKeeper = require("electron-window-state"); const path = require('path'); const ioHook = require('iohook');

let win; let webContents;

function createWindow() { const mainWindowState = windowStateKeeper({ defaultHeight: 800, defaultWidth: 800, })

win = new BrowserWindow({
    x: mainWindowState.x,
    y: mainWindowState.y,
    height: mainWindowState.height,
    width: mainWindowState.width,
    webPreferences: {
        nodeIntegration: true,
        contextIsolation: false,
    },
    'web-preferences': {
        'web-security': false
    }
});

webContents = win.webContents;
win.loadURL("file://"+ path.join(__dirname, "../build/index.html#/"))

win.webContents.openDevTools();
mainWindowState.manage(win);

ioHook.on("keypress", event => {
    console.log(event);    });
ioHook.start();

}

app.whenReady().then(createWindow);

silviawxy commented 4 months ago

have you resolved? i got the same problem

vimalAtLR commented 4 months ago

have you resolved? i got the same problem

Yes I resolved it. The module iohook was not getting found after I create a build because the process was little bit wrong. Assuming that you are using reactjs for UI.

Delete node_modules and run "npm install" first. Then you need to run "PUBLIC_URL='./' npm run build" command as we are doing in all react applications. It will create a production build. Here we have to pass public url by which our react production build will be generate correctly and will get packages correctly from the node_modules.

scripts in package.json file will look like this "build": "react-scripts build", "builder": "electron-builder build",

Note: for every platform when you create a build, you need to pass public url. linux: "PUBLIC_URL='./' npm run build" windows: "$env:PUBLIC_URL='./'; npm run build" mac: "PUBLIC_URL='./' npm run build"

Hope this will become helpful to you.

florish-lacy commented 4 months ago

Please PR if there are problems with the documentation!