Comments (12)
After exhausting days of searching and debugging, I found the solution to the problem!!
Apparently it's an import error from the "vue-cli-plugin-electron-builder" package. See docs
You just need to add the following configuration:
// vue.config.js
module.exports = {
pluginOptions: {
electronBuilder: {
// List native deps here if they don't work
externals: ['electron-pos-printer'],
// If you are using Yarn Workspaces, you may have multiple node_modules folders
// List them all here so that VCP Electron Builder can find them
nodeModulesPath: ['../../node_modules', './node_modules']
}
}
}
from electron-pos-printer.
I believe it is an error with the node version, possibly reverting to an older version resolves it, but not ideal and this will probably upset some other package you are using. This is why I made my own package, though I have not utilized it in a while, so I am not sure how well it is working with the current version of node
from electron-pos-printer.
If you are using electron 12 or greater just move to
ipcMain
andipcRenderer
, I've tried also@electron/remote
but it's the same error.Code example:
// === in renderer code import { ipcRenderer } from 'electron'; // in some async function ... const printers = await ipcRenderer.invoke('serivce-printer-list'); const data = [ ... ]; // data to print const options = { printerName: printers[0], // a printer from the printers list // ... other options }; try { await ipcRenderer.invoke('serivce-printer-print', (data, options)); } catch(err) { console.error(err); } // === in main code const { app, BrowserWindow, ipcMain } = require('electron'); const { PosPrinter } = require('electron-pos-printer'); // main window init logic const mainWindow = new BrowserWindow({ ... }); ipcMain.handle('service-printer-list', async () => { const webContents = mainWindow.webContents; const printers = webContents.getPrinters(); return printers; }); ipcMain.handle('service-printer-list', async (data, options) => PosPrinter.print(data, options));
I try this and modify the code it's working, but the printer doesn't do anything. i try set print preview: true
in options, it run but not showing of the content.
after I inspect the element an error appears:
and this my code.
// === in main code ( background.js )
import { app, protocol, BrowserWindow, ipcMain } from 'electron'
const { PosPrinter } = require('electron-pos-printer');
const mainWindow = new BrowserWindow({ ... });
const options = {
preview: true, // Preview in window or print
width: 250, // width of content body
margin: "0px 0px 0px -10px", // margin of content body
copies: 1, // Number of copies to print
printerName: 'POS58 Printer(3)', // printerName: string, check it at webContent.getPrinters()
timeOutPerLine: 500,
silent: true,
};
ipcMain.handle('service-printer-print', (data) =>{
PosPrinter.print(data, options);
});
// === in renderer code ( invoice.vue )
import { ipcRenderer } from 'electron';
export default{
data(){
return {
datass:[]
}
}
methods: {
async printr() {
try {
await ipcRenderer.invoke('service-printer-print', (this.datass));
} catch(err) {
console.error(err);
}
},
}
}
And i try disable webSecurity in my vue.config.js
but still not working.
how about this?
from electron-pos-printer.
@Ahmed-dev-vpc https://www.npmjs.com/package/electron-epos-printer - created this package, it does not do as much as this one, but it builds for me. Feel free to open some issues if you want to see extra features in it.
from electron-pos-printer.
@davimatos
Yeah, that's what happened to me too :)
After a very hard search, this was just the solution
// vue.config.js
module.exports = {
pluginOptions: {
electronBuilder: {
....
externals: ['electron-pos-printer'],
...
}
}
}
from electron-pos-printer.
Did you find a solution to this?
from electron-pos-printer.
Did you find a solution to this?
not yet :(
from electron-pos-printer.
If you are using electron 12 or greater just move to ipcMain
and ipcRenderer
, I've tried also @electron/remote
but it's the same error.
Code example:
// === in renderer code
import { ipcRenderer } from 'electron';
// in some async function ...
const printers = await ipcRenderer.invoke('serivce-printer-list');
const data = [ ... ]; // data to print
const options = {
printerName: printers[0], // a printer from the printers list
// ... other options
};
try {
await ipcRenderer.invoke('serivce-printer-print', (data, options));
} catch(err) {
console.error(err);
}
// === in main code
const { app, BrowserWindow, ipcMain } = require('electron');
const { PosPrinter } = require('electron-pos-printer');
// main window init logic
const mainWindow = new BrowserWindow({ ... });
ipcMain.handle('service-printer-list', async () => {
const webContents = mainWindow.webContents;
const printers = webContents.getPrinters();
return printers;
});
ipcMain.handle('service-printer-list', async (data, options) => PosPrinter.print(data, options));
from electron-pos-printer.
@robert52 @O-ID @Drewdan @sidneip
Hi guys
Are there other packages that do the same thing as an electron-post-printer?
from electron-pos-printer.
I created a custom implementation of my own to handle printing using an EPOS printer, it created headings, paragraphs and tables. I can pull this into a package and put some docs together is people are interested
from electron-pos-printer.
I have the same problem. It only happens in production. Any solution? :(
from electron-pos-printer.
I believe it is an error with the node version, possibly reverting to an older version resolves it, but not ideal and this will probably upset some other package you are using. This is why I made my own package, though I have not utilized it in a while, so I am not sure how well it is working with the current version of node
Thanks for help. Do you have documentation for this package you created, or does it work the same as this one?
from electron-pos-printer.
Related Issues (20)
- Documents larger than the electron window do not print completely. HOT 3
- Sample: type text can be an html string HOT 1
- dist folder deleted HOT 5
- Cannot find module 'electron-pos-printer' or its corresponding type declarations. I am using nextron HOT 1
- version 1.3.7 have no dist folder in node modules , so it is throwing error, 1.3.6 works fine HOT 8
- [1092:0605/115531.410:ERROR:print_render_frame_helper.cc(2264)] Printing failed. HOT 17
- Paper Size Issue - Only in Ubuntu
- Length of label is really long and unable to shorten it.
- Can't configure the package using electron-vuejs
- Cannot find module 'electron-pos-printer' or its corresponding type declarations. HOT 3
- Image width MINE type url can't work accurately.
- [Fix] - Silent Print not wokring. HOT 6
- Incomplete printing due to low PC configuration Win7 and asynchronous issues
- Retruns undefined
- Throw a timeout exception HOT 1
- 1.3.7 has no `/dist` on npm HOT 4
- Margin, table padding, default font HOT 1
- Not able to hide the Border between Row with type = TABLE HOT 3
- Pass custom html file to to pathTemplate HOT 1
- Thermal print is breaking to pieces (Multiple pages) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electron-pos-printer.