serialport / node-serialport

Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!
https://serialport.io
MIT License
5.8k stars 1.01k forks source link

Serialport package issue after electron build with electron-builder #2542

Open megha24051994 opened 2 years ago

megha24051994 commented 2 years ago

SerialPort Version

10.0.0

Node Version

14.19.0

Electron Version

19.0.0

Platform

x64

Architecture

No response

Hardware or chipset of serialport

No response

What steps will reproduce the bug?

Using serialport in an electron-ionic project in the renderer side. Serialport package is installed and loaded into the project as follows in the serialport service constructor:

this.serialport = window.require('serialport');

The project works and serialport list function works when the electron window is opened using the command npx cap open @capacitor-community/electron.

There are 2 issues afterwhich:

  1. The port creation doesn't work and but doesn't throw any error to analyse the issue. Also tried adding it with a catch statement. this.port= new this.serialport .SerialPort(serialDevice.name, { baudRate: 9600, autoOpen: false });
  2. After building the electron project using electron-builder, the serialport module isn't detected anymore and throws the error 'Cannot find module serialport'. image

What happens?

In an electron-ionic project, the serialport package (v10.0.0) works when the electron window is opened in Dev mode using 'npx cap open @capacitor-community/electron' but it throws an error "Cannot find module 'serialport'" when the project is build using electron-builder.

What should have happened?

Serialport package should work with the build exe as well.

Additional information

No response

Dardin-dale commented 1 year ago

I recommend putting Serialport on the main process and not the renderer process. You can use Electron's IPC handlers to call your serialport interface from the renderer process.