Klemen1337 / node-thermal-printer

Node.js module for Epson, Star, Tanca, Drauma and Brother thermal printers command line printing.
MIT License
761 stars 241 forks source link

Implementation in React Js. fs module not found #173

Closed theonardo23 closed 2 years ago

theonardo23 commented 3 years ago

I'm building a web app using React JS with typescript with Epson TM-U220D as the printer. I've done setting everything up, but when I try to run it, it always throws error related to fs. I've checked on my node-module/node and fs is there. Here's how I setup my printing page.

import React, { FunctionComponent } from 'react'
import { Button } from 'react-bootstrap'
import ThermalPrinter from 'node-thermal-printer'

export const PrintReceipt : FunctionComponent<> = () => {

    const printerNew = new ThermalPrinter.printer({
        type: ThermalPrinter.types.EPSON,
        interface: '/dev/usb/lp0'
    })

    const handlePrint = () =>{
        printItem()
    }

    const printItem = async() =>{
        const isConnected = await printerNew.isPrinterConnected()
        printerNew.println('Hello World')
        const result = await printerNew.execute()
        console.log(result)
    }

    return(
        <Button onClick={handlePrint}>Print Receipt</Button>
    )
}

For the code above it throws the error fs.existsSync is not a function . Is it anything to do with the project being build in typescript?

Klemen1337 commented 3 years ago

This is NodeJS project. I also made a browser friendly version https://github.com/Klemen1337/browser-thermal-printer