Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error importing in common js #88

Open
Jonnykoder opened this issue Feb 27, 2024 · 1 comment
Open

Error importing in common js #88

Jonnykoder opened this issue Feb 27, 2024 · 1 comment

Comments

@Jonnykoder
Copy link

Jonnykoder commented Feb 27, 2024

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
Copy link

Hi, maybe this will solve your problem:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants