I have tried a number of library, some do not even install with npm install
especially printer
and electron
. Other Libraries I was able to either throws an internal error that is not from my code or they work in development and fail in the production server render
Below is what I currently have with electron-pos-printer
, please any modification or suggestion with the kind of environment I have will be appreciated alot! Thanks
const { PosPrinter } = require("electron-pos-printer");
const path = require("path");
async function printReceipt(data) {
try {
const options = {
preview: false,
margin: "0 0 0 0",
copies: 1,
printerName: "XP-80C",
timeOutPerLine: 400,
pageSize: { width: 80, height: 297 },
silent: true,
};
const {
items,
} = data;
const receiptData =
{
type: "text",
value: items.length,
style: `text-align:center;`,
},
{
type: "text",
value: "nnn",
},
// other data
];
PosPrinter.print(receiptData, options)
.then(console.log)
.catch((error) => {
throw new Error(error.message);
});
} catch (error) {
console.log(error);
throw new Error("Failed to print receipt");
}
}
module.exports = {
printReceipt,
};
This particular code gives the error below:
throw new Error(error.message);
^
Error: r.BrowserWindow is not a constructor
at C:UsersAdminDesktopcodingInventoryinventory-apputilsprintReceipt.js:200:15
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v18.20.4
If you have any other suggestion that I can use as a replacement for this for the MERN stack environment, it will be much appreciated!