question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Driver is undefined while calling `getPrinter`

See original GitHub issue

Getting following error when I try to print a page

"TypeError: Cannot read property 'getPrinter' of undefined"

The error happens when executing /lib/interfaces/printer.js:31

  if (this.driver.getPrinter(this.getPrinterName())) { ...

Because it doesn’t meet the condition in the constructor to set driver.

  constructor(printerName, moduleName) {
    super();
    this.name = printerName;
    if (moduleName && typeof moduleName === "object") {
      this.driver = moduleName;
    }

I wonder what is supposed to pass as the second argument here and why it may be undefined? /lib/interfaces/index.js:17

  } else if (printer) {
    const Printer = require('./printer');
    return new Printer(printer[1], printer[2]);

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
vadhackcommented, Dec 5, 2019

@Klemen1337 Yes, I realized, thank you.

@ertankara the correct way is:

      let printer = new ThermalPrinter({
        type: PrinterTypes.STAR,
        // I've also tried "printer:auto" both of them gives the same result
        // "TypeError: Cannot read property 'getPrinter' of undefined"
        interface: "printer:Star TSP100 Cutter (TSP143)",
        characterSet: "SLOVENIA",
        options: {
          timeout: 5000
        },
        driver: require(electron ? 'electron-printer' : 'printer'), // setting driver module
      });
      // Error is thrown when executing line below
      let isConnected = await printer.isPrinterConnected();
0reactions
ertankaracommented, Dec 5, 2019

@Klemen1337

Using the code below in an Electron project.


  const ThermalPrinter =  require("node-thermal-printer").printer;
  const PrinterTypes = require("node-thermal-printer").types;


  let printer = new ThermalPrinter({
        type: PrinterTypes.STAR,
        // I've also tried "printer:auto" both of them gives the same result
        // "TypeError: Cannot read property 'getPrinter' of undefined"
        interface: "printer:Star TSP100 Cutter (TSP143)",
        characterSet: "SLOVENIA",
        options: {
          timeout: 5000
        }
      });
      // Error is thrown when executing line below
      let isConnected = await printer.isPrinterConnected();

By the way this is of course in an async function, I didn’t include function signature.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webdriver: Undefined name 'driver' - python - Stack Overflow
When testing if browser is already opened, there is a message in Spyder's editor: undefined name 'driver'. How to change the code to...
Read more >
Win32 API GetPrinter function help - Page 2 - NI Community
Solved: I am using the WInspool.drv to determine printer status. Using that DLL, I am trying to execute the GetPrinter function. When I ......
Read more >
WINPRINT-GET-PRINTER-INFO-EX - Micro Focus
WINPRINT-CURR-COLLATE, Determines if the collating feature of the currently selected printer is turned on or off. ; WINPRINT-CURR-PAPERSIZE, Returns the current ...
Read more >
GetPrinter function (Winspool.h) - Win32 apps | Microsoft Learn
The GetPrinter function retrieves information about a specified printer. ... When this happens, the printer is unusable until the driver is ...
Read more >
Solved: get printer out of mfg mode - Page 6 - HP Community
When I switched on this evening some 7 or 8 updated drivers automatically ... this and maybe I have to call HP UK...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found