Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node-serialport does not work with Electron

My task is to build a HTML5 desktop app, which works with serial port, because I have an arduino on the other side on COM-port.

I installed electron-prebuilt and serialport packages both (I specified them in package.json). In my main web page I included main.js, and there I tried to require the serialport package, but I got the following error:

Uncaught Error: Cannot find module 'D:\Projects\arduino\HTMLPresentation\node_modules\serialport\build\serialport\v1.7.4\Release\node-v45-win32-x64\serialport.node'

I've read some QA topics about that problem (some abracadabras with node-gyp), but noting works for me: on both windows 8.1 and Ubuntu 15.04. I don't know how to adopt serialport package for electron.

like image 882
Rainman Avatar asked Sep 12 '15 09:09

Rainman


1 Answers

My enviroment:

Vue.js: 2.6.10
Electron: 2.0.18
Node: 8.9.3
Platform: linux

If you are using Eletron with Vue.js you need to rebuild the serialport module doing something like this:

npm install electron-rebuild --save-dev

after this, you can add in your package.json > section "scripts", another line saying:

"rebuild": "electron-rebuild -f -w serialport"

You can rebuild the module with terminal command

npm run rebuild

Now the serialport module should be imported and will work as expected. Goog luck!

like image 193
Razvan Theodor Avatar answered Nov 15 '22 03:11

Razvan Theodor