iohook icon indicating copy to clipboard operation
iohook copied to clipboard

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'

Open vimalAtLR opened this issue 2 years ago • 3 comments
trafficstars

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:

  • /home/logicrays/Documents/practice project/Learn electronjs/web-tracker-electron-app/node_modules/iohook/index.js
  • /home/logicrays/Documents/practice project/Learn electronjs/web-tracker-electron-app/public/electron.js
  • /home/logicrays/Documents/practice project/Learn electronjs/web-tracker-electron-app/node_modules/electron/dist/resources/default_app.asar/main.js
  • at Module._resolveFilename (node:internal/modules/cjs/loader:1002:15) at n._resolveFilename (node:electron/js2c/browser_init:2:109797) at Module._load (node:internal/modules/cjs/loader:848:27) at f._load (node:electron/js2c/asar_bundle:2:13330) at Module.require (node:internal/modules/cjs/loader:1068:19) at require (node:internal/modules/cjs/helpers:103:18) at Object. (/home/logicrays/Documents/practice project/Learn electronjs/web-tracker-electron-app/node_modules/iohook/index.js:24:21) at Module._compile (node:internal/modules/cjs/loader:1174:14) at Module._extensions..js (node:internal/modules/cjs/loader:1229:10) at Module.load (node:internal/modules/cjs/loader:1044:32)

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);

vimalAtLR avatar Mar 30 '23 12:03 vimalAtLR

have you resolved? i got the same problem

silviawxy avatar Feb 20 '24 09:02 silviawxy

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.

vimalAtLR avatar Feb 20 '24 09:02 vimalAtLR

Please PR if there are problems with the documentation!

florish-lacy avatar Mar 05 '24 02:03 florish-lacy