Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Mar 30, 2023 · 3 comments

Comments

@vimalAtLR
Copy 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'
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);

@silviawxy
Copy link

have you resolved? i got the same problem

@vimalAtLR
Copy link
Author

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
Copy link

Please PR if there are problems with the documentation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants