Search code examples
javascriptwebpackcommonjsthermal-printerepson

How to include Epson SDK for JavaScript in CommonJS project


I have a project with WebPack, where modules are imported with CommonJS structure.

Now I need to import the ePOS_SDK_JavaScript_v2.7.0 library (file "epos-2.7.0.js").
But it is not a valid CommonJS module.

How can I import the library in my project?

Thanks


Solution

  • After some hours I found a simplest solution.

    1) edit epos-2.7.0.js file
    Insert this row in top of file:

    var io = module.exports;
    

    2) import the library
    The SDK is not pretty recognized by CommonJS, then it is required to declare the epson variable:

    import '../<path>/epos-2.7.0.js';
    declare var epson;
    

    For TypeScript projects

    import '../<path>/epos-2.7.0.js';
    declare var epson: any;