node-escpos / driver

🖨️ ESC/POS Printer driver for Node.js.
Other
317 stars 32 forks source link

Error importing in common js #88

Open Jonnykoder opened 9 months ago

Jonnykoder commented 9 months ago

Hi, this is a great library. However, Im having a bit of a problem when importing this to my recent project (common js) which uses https://github.com/song940/node-escpos.

So my current implementation of node-escpos uses an import like this

// my printer vendorId
const vendorId = '0x0483'

//my printer product id
const ProductId = '0x5743'

const escpos = require("escpos");
const device = new escpos.USB(vendorId, productId);
let printer = new escpos.Printer(device);

 if (device != null) {
   device.open(function () {
          printer
            .font("a")
            .align("ct")
            .style("bu")
            .size(1, 1)
            .text("Testing Printer")
            .text("The quick brown fox jumps over the lazy dog")
            .barcode("6611235132450000000000", "CODE93", {
              height: 35,
              width: 1,
            })
            .control("lf");
          printer.cut();
          printer.close();

   }
 }

Here is what I've tried so far on import

"use strict";

var _core = require("@node-escpos/core");
var _usbAdapter = _interopRequireDefault(require("@node-escpos/usb-adapter"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

here is the error message being rendered on the console


node_modules\@node-escpos\core\dist\index.mjs:1
(function (exports, require, module, __filename, __dirname, process, global, Buffer) { return function (exports, require, module, __filename, __dirname) { import EventEmitter from 'eventemitter3';
lucasaugusto-silva commented 4 months ago

Hi, maybe this will solve your problem:

const { Printer } = await import('@node-escpos/core'); const { default: USB } = await import('@node-escpos/usb-adapter');