Panagiotis Koursaris Panagiotis Koursaris - 3 months ago 92
TypeScript Question

Using external library with angular cli

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?


Have a look at the instructions here:‌​n.

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 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 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.