-3

I`ve got some trouble with the electron. When I'm running my js code, it's working, but when i start electron with this code, it's not working

var i = 0
alert('1');
const SerialPort = require('serialport')
alert('1');
const Readline = SerialPort.parsers.Readline
const port = new SerialPort('/dev/pts/2')
const parser = new Readline()
port.pipe(parser)
parser.on('data',function (data) 
{
  console.log('Data:', data);
  //DoSomeStuff(data);
  //document.write(data);
})

function DoSomeStuff(data){
  alert(data);
}

This code is reading what i'm writing in emulation of COM port and past in the console, and alert whats data i transfer from one port to another

Error

Uncaught Error: The module '/home/user/node_modules/@serialport/bindings/build/Release/bindings.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 64. This version of Node.js requires NODE_MODULE_VERSION 70. Please try re-compiling or re-installing the module (for instance, using npm rebuild or npm install). at process.func [as dlopen] (electron/js2c/asar.js:155)...

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Wart Vader
  • 11
  • 2
  • `it's not working`, what's the problem ? You have a crash, output is null, empty ? Please add details – Maelig Jun 06 '19 at 07:57
  • no it's working when i start just js code without electron – Wart Vader Jun 06 '19 at 07:58
  • Does electron give any error messages? – mplungjan Jun 06 '19 at 07:58
  • @mplungjan, i don't know. How to see this error message? – Wart Vader Jun 06 '19 at 07:59
  • https://stackoverflow.com/questions/30814336/error-messages-and-console-logs-in-electron – mplungjan Jun 06 '19 at 08:05
  • @mplungjan, thx, I will check this. – Wart Vader Jun 06 '19 at 08:07
  • @mplungjan, I got this error: Uncaught Error: The module '/home/user/node_modules/@serialport/bindings/build/Release/bindings.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 64. This version of Node.js requires NODE_MODULE_VERSION 70. Please try re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`). at process.func [as dlopen] (electron/js2c/asar.js:155)... – Wart Vader Jun 06 '19 at 08:54
  • Possible duplicate of [Node - was compiled against a different Node.js version using NODE\_MODULE\_VERSION 51](https://stackoverflow.com/questions/46384591/node-was-compiled-against-a-different-node-js-version-using-node-module-versio) – snwflk Jun 06 '19 at 13:18

1 Answers1

1

I change package.json

package.json:

 {
  "name": "electron-quick-start",
  "version": "1.0.0",
  "description": "A minimal Electron application",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "repository": "https://github.com/electron/electron-quick-start",
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": {
    "electron": "^5.0.2",
    "electron-rebuild": "^1.8.5"
  },
  "dependencies": {
    "serialport": "^7.1.5"
  }
}

Download electron-rebuild, and then download serialport npm install -g serialport. After all of that I did:

$ npm install
$ ./node_modules/.bin/electron-rebuild
$ npm start

And it's working fine now

Wart Vader
  • 11
  • 2