GithubHelp home page GithubHelp logo

Comments (12)

davimatos avatar davimatos commented on July 17, 2024 4

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.

Drewdan avatar Drewdan commented on July 17, 2024 2

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.

odysahe avatar odysahe commented on July 17, 2024 1

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));

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:

image

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.

Drewdan avatar Drewdan commented on July 17, 2024 1

@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.

Ahmed-Sarmoum avatar Ahmed-Sarmoum commented on July 17, 2024 1

@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.

Drewdan avatar Drewdan commented on July 17, 2024

Did you find a solution to this?

from electron-pos-printer.

Ahmed-Sarmoum avatar Ahmed-Sarmoum commented on July 17, 2024

Did you find a solution to this?

not yet :(

from electron-pos-printer.

robert52 avatar robert52 commented on July 17, 2024

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.

Ahmed-Sarmoum avatar Ahmed-Sarmoum commented on July 17, 2024

@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.

Drewdan avatar Drewdan commented on July 17, 2024

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.

davimatos avatar davimatos commented on July 17, 2024

I have the same problem. It only happens in production. Any solution? :(

from electron-pos-printer.

davimatos avatar davimatos commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.