pptxgenjs: This expression is not constructable

134 Views Asked by At

I am new to NodeJS.

I'm trying to write the following code for a NodeJS application (in src/index.ts):

import pptxgenjs from 'pptxgenjs';
const pres = new pptxgenjs();

Source

But the Typescript compiler gives me the following error:

This expression is not constructable.
Type 'typeof import("########/node_modules/pptxgenjs/types/index")' has no construct signatures.

My tsconfig.json looks like this:

{
    "compilerOptions": {
        "module": "NodeNext",
        "moduleResolution": "NodeNext",
        "target": "ES2020",
        "sourceMap": true,
        "outDir": "dist",
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true
    },
    "include": ["src/**/*"]
}

What can I do to resolve this?

1

There are 1 best solutions below

1
Emmanuel On

It looks like I am using the exact same code on a typescript project and it works for me.

import pptxgen from "pptxgenjs";
let pres: pptxgen
pres = new pptxgen();

It is inside a NextJs typescript project.

Below is the beginning of my tsconfig.json file. Hope this helps.

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "esnext",
    "module": "es2020",
    "lib": [
      "esnext",
      "dom"
    ],
    "jsx": "preserve",
    "moduleResolution": "node",
    "strict": true,
    "sourceMap": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "noEmit": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "typeRoots": [
      "./node_modules/@types",
    ],
    "allowJs": true,
    "incremental": true,
    "isolatedModules": true,
    "plugins": [
      {
        "name": "next"
      }
    ]
  },