node-serialport
node-serialport copied to clipboard
Serialport package issue after electron build with electron-builder
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:
- 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 });
- After building the electron project using electron-builder, the serialport module isn't detected anymore and throws the error 'Cannot find module serialport'.
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
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.