3

I have installed one 3rd party module jsPDF with my angular app. The module works perfectly but I get an error in my console:

Cannot find module '../../../node_modules/jspdf/dist/jspdf.min.js'.

What I did:

  1. Install the module via npm:

npm install MrRio/jsPDF --save

  1. Import the module in my component:

import * as jsPDF from '../../../node_modules/jspdf/dist/jspdf.min.js';

  1. Then simply works with this module in my component.

Is something missing here?

3
  • Have a look at the instructions here: github.com/angular/angular-cli#3rd-party-library-installation. If jsPDF needs to be in the global scope, you will need to add the JS file to apps[0].scripts in your angular-cli.json file, which WebPack then bundles as if it were loaded with a <script> tag. If you do the latter, you can get at it by adding declare var jsPDF: any; in your src/typings.d.ts or component. However, it looks like there are typings for jsPDF npmjs.com/package/@types/jspdf so you can include it; but you should be able to import { jsPDF} from 'jspdf'; Commented Nov 10, 2016 at 11:39
  • @Harry Thank you. You could post this as an answer so I can accept it. Commented Nov 10, 2016 at 12:40
  • Glad it worked, thank you, I've added it as an answer. Commented Nov 10, 2016 at 12:45

1 Answer 1

6

Have a look at the instructions here: github.com/angular/angular-cli#3rd-party-library-installatio‌​n.

If jsPDF (or any other library) needs to be in the global scope, you will need to add the JS file to apps[0].scripts in your angular-cli.json file, which WebPack then bundles as if it were loaded with a <script> tag. If you do that, you can get at it by adding declare var jsPDF: any; in your src/typings.d.ts or component.

However, it looks like there are typings for jsPDF npmjs.com/package/@types/jspdf so you can include it after running npm install --save-dev @types/jspdf; you should be able to import { jsPDF } from 'jspdf'; in your component.

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

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.