TypeError: Argument 1 must be a string when execute printer_helper.printDirect(data, printer, docname, type, options);
Hi, i've been testing using the print_raw.js example, i use electron-forge to create new project, then do npm install printer --runtime=electron --target=3.3.1 --target_arch=x64 from new project directory.
here's my index.js from the project's src :
import { app, BrowserWindow } from 'electron';
// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require('electron-squirrel-startup')) { // eslint-disable-line global-require
app.quit();
}
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
var printer = require("../node_modules/printer/lib");
const createWindow = () => {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
});
// and load the index.html of the app.
mainWindow.loadURL(`file://${__dirname}/index.html`);
// Open the DevTools.
mainWindow.webContents.openDevTools();
printer.printDirect({data:"print from Node.JS buffer" // or simple String: "some text"
//, printer:'Foxit Reader PDF Printer' // printer name, if missing then will print to default printer
, type: 'RAW' // type: RAW, TEXT, PDF, JPEG, .. depends on platform
, success:function(jobID){
console.log("sent to printer with ID: "+jobID);
}
, error:function(err){console.log(err);}
});
// Emitted when the window is closed.
mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
};
. . . . . . . . . . . . .
and here's the electron-forge start result from the terminal(i'm using Debian x64)
wisdompos@debian-e5510:~/Work/electron-pos-project$ electron-forge start ✔ Checking your system ✔ Locating Application ✔ Preparing native dependencies: 1 / 1 ✔ Launching Application print from Node.JS buffer undefined node print job RAW {} // above was debug info from console.log(data);console.log(printer);console.log(docname);console.log(type);console.log(options);
TypeError: Argument 1 must be a string at Object.printDirect (/home/wisdompos/Work/electron-pos-project/node_modules/printer/lib/printer.js:238:38) at App.createWindow (/home/wisdompos/Work/electron-pos-project/src/index.js:29:11) at emitTwo (events.js:130:20) at App.emit (events.js:213:7)
As far i just search the passed undefined argument should be ok? I was testing on windows before this, on windows i need to install electron-prebuild-compile and some edit on the package.json(not related to node printer) but after it the electron-forge start is working without any error and i can see the print job being sent to printer task.
Sorry if this appear to be caused by my setup incompleteness.