Reputation: 4023
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:
npm install MrRio/jsPDF --save
import * as jsPDF from '../../../node_modules/jspdf/dist/jspdf.min.js';
Is something missing here?
Upvotes: 3
Views: 7665
Reputation: 3412
Have a look at the instructions here: github.com/angular/angular-cli#3rd-party-library-installation.
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.
Upvotes: 6