Reputation: 41
I am trying to use PptxGenJS.
I installed it by npm install pptxgenjs --save
I created very simple function, according to the examples.
When I am doing: import * as PptxGenJS from 'pptxgenjs';
const pptx = new PptxGenJS();
I am getting error "pptxgenjs__WEBPACK_IMPORTED_MODULE_2__ is not a constructor"
When I am doing:
let PptxGenJS = require("pptxgenjs");
let pptx = new PptxGenJS();
I am getting the error: "TypeError: PptxGenJS is not a constructor"
I am using 3.0.1 with Angular8 on Ubuntu
Upvotes: 2
Views: 1573
Reputation: 41
I find out that using pptxgenjs-angular works fine.
What I done is:
import * as PptxGenJS from 'pptxgenjs-angular';
const pptx = new PptxGenJS();
For some unknown reason, PptxGenJS failed to find the JSZip.
So I create ZIP object in my function, and send it as new parameter to
const JSZip = require('jszip');
var zip = new JSZip();
pptx.save(fileName, null, null, zip);
Upvotes: 0
Reputation: 102
make sure to allow synthetic default imports and esModule interoperability in your tsconfig file:
"angularCompilerOptions": {
...
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
}
then import in into your component like this:
import PptxGenJS from 'pptxgenjs'
use like this:
ppt = new PptxGenJS();
Upvotes: 0
Reputation: 46
I faced same issue. Import correct file, then it should work,
import pptxgen from "pptxgenjs";
let pres = new pptxgen();
let slide = pres.addSlide();
let textboxOpts = { x: 1, y: 1, w: '80%', h: 0.5, align: 'center', color: '131A1A', fill: 'B2E8ED', fontSize: 20 };
slide.addText("Sample text", textboxOpts);
pres.writeFile("Sample Presentation.pptx");
Upvotes: 0