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


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:


printJS


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.





Try to import the non minified version of the script
– bambam
Jun 29 at 10:48





@bambam I changed import to import { printJS } from "print-js/dist/print.js"; it compiles without any errors but the problem is the same.
– XardasLord
Jun 29 at 10:50


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





Ah it's a node_module.. dfsq's answer should solve it then.
– bambam
Jun 29 at 10:52




1 Answer
1



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.


print-js





Thank you for the solution, it works nice! And thanks for the advice I will keep that in my mind :)
– XardasLord
Jun 29 at 10:57






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV