2

I had integrated OpenTok.js library for video call in my electron app, for which i want to use logitech device and to use it i need node-hid library using which my app can detect device.

I had done all the needful mentioned for using node-hid in Electron projects, package did get installed but when i require it in my js file using :-

var HID = require('node-hid');
var devices = HID.devices();

And run my app , it gives an error

Error: Module version mismatch. Expected 50, got 51. So please help me with this issue .

Thanks

varun
  • 21
  • 4

2 Answers2

4

Use electron-rebuild for rebuild modules for suitable for electron. Some node modules are not exactly suitable for electron, because electron uses it's own build of Node. So, electron-rebuild will sort out any incompatibility or functional issues of node modules we use. The recommended way it to add "postinstall": "electron-rebuild --force" line to scripts of package.json file.

One other thing, on linux when you run dev mode, you have to run the script as sudo. Otherwise it'll rise another issue like cannot open device with path...

hope this help someone... :)

Tharanga
  • 2,689
  • 1
  • 21
  • 18
  • I have the same error and nothing is helping. I tried your solution. Also there is no webpack.config in my blank reactjs project. – Kingalione Jan 15 '20 at 16:18
  • I require a node-hid build for Win32 x32 / ia32, at a linux CI pipeline... Any idea? Because this prebuild for node-hid doesn't exist for Win32 x32 / ia32. – Ronye Vernaes Apr 01 '20 at 10:06
1

I encountered this issue myself, and thought I would share the solution that worked for me. @Tharanga is correct - the recommended way to get around this is to include the below in package.json "scripts" section:

    "postinstall": "electron-rebuild --force"

However, I have experienced inconsistent success with that approach.

Another approach is, after installing "node-hid", run this (if on mac):

    .\node_modules\.bin\electron-rebuild

Or for Windows:

    .\node_modules\.bin\electron-rebuild.cmd

Finally, if you are using webpack in your project, you must add this line to your webpack.config.js file (within module.exports block):

    externals: {
        "node-hid" : 'commonjs node-hid'
    }

I hope this helps some folks in the future!

LukeT
  • 340
  • 2
  • 9