I am using node-thermal-printer package from github ( https://github.com/Klemen1337/node-thermal-printer ) in order to print on Esc-pos printer.
When I try to print, I get error : Unhandled Rejection (TypeError): Net.connect is not a function
I searched a lot and there was only one unanswered question like mine here: https://gitter.im/Klemen1337/node-thermal-printer?at=588fbd82c0f28dd862629227
I am trying to print from Reactjs project using Chrome on Mac, I tried it on Android device too but I get the same issue.
I installed all the dependencies like : net, write-file-queue, unorm, iconv-file too.
This is the print image code:
testPrint = async () => {
const ThermalPrinter = require("../../../node_modules/node-thermal-printer")
.printer;
const Types = require("../../../node_modules/node-thermal-printer").types;
let printer = new ThermalPrinter({
type: Types.EPSON,
interface: "tcp://192.168.0.100:9100"
});
printer.alignCenter();
printer.println("Hello world");
try {
let execute = printer.execute();
console.error("Print done!");
} catch (error) {
console.log("Print failed:", error);
}
};
and the problem happens in "var printer = Net.connect(" copied from network.js file of the package as below:
async execute(buffer) {
return new Promise((resolve, reject) => {
let name = this.host + ":" + this.port;
var printer = Net.connect(
{
host: this.host,
port: this.port,
timeout: this.timeout
},
function () {
printer.write(buffer, null, function () {
resolve("Data sent to printer: " + name);
printer.destroy();
});
}
);
printer.on('error', function (error) {
reject(error);
printer.destroy();
});
printer.on('timeout', function () {
reject(new Error("Socket timeout"));
printer.destroy();
});
});
}}
Any advice would be appreciated.