3

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.

3
  • Try to import the non minified version of the script Commented Jun 29, 2018 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. Commented Jun 29, 2018 at 10:50
  • Ah it's a node_module.. dfsq's answer should solve it then. Commented Jun 29, 2018 at 10:52

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the solution, it works nice! And thanks for the advice I will keep that in my mind :)
1
  1. npm i print-js --save
  2. import * as printJS from 'print-js';

It works for me in the project using Angular 12

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.