javascriptangulartypescriptprintjs

Angular printjs: ERROR TypeError: Object(...) is not a function


I'm trying to use printJS in Angular and print an image (PNG). I did the import:

    import { printJS } from "print-js/dist/print.min.js";

Then I execute this printing code in function, according to the documentation:

    printJS('no-image.png', 'image');

I got following error: enter image description here

I can't find solution to fix this.


Solution

  • I think you need to use default import for this library:

    import printJS from "print-js";
    

    Also, for NPM packages you should never import directly from js path. Usually you would just import from package itself, in your case print-js.