node-thermal-printer-js 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app.js +7 -5
- package/package.json +1 -1
package/app.js
CHANGED
|
@@ -62,18 +62,20 @@ const printViaComPort = async (data, options = {}) => {
|
|
|
62
62
|
const baudRate = options.baudRate || 9600;
|
|
63
63
|
|
|
64
64
|
// Dynamically import `serialport` only when COM transport is requested.
|
|
65
|
-
let
|
|
65
|
+
let SerialPortCtor;
|
|
66
66
|
try {
|
|
67
|
-
SerialPortModule = await import("serialport");
|
|
67
|
+
const SerialPortModule = await import("serialport");
|
|
68
|
+
SerialPortCtor = SerialPortModule.SerialPort || SerialPortModule.default;
|
|
69
|
+
|
|
70
|
+
if (!SerialPortCtor) {
|
|
71
|
+
throw new Error("SerialPort constructor not found in module exports");
|
|
72
|
+
}
|
|
68
73
|
} catch (e) {
|
|
69
74
|
return Promise.reject(
|
|
70
75
|
new Error(`serialport module not available: ${e.message}`),
|
|
71
76
|
);
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
const SerialPortCtor =
|
|
75
|
-
SerialPortModule.default || SerialPortModule.SerialPort || SerialPortModule;
|
|
76
|
-
|
|
77
79
|
const port = new SerialPortCtor({
|
|
78
80
|
path: portPath,
|
|
79
81
|
baudRate,
|