Context
I am trying to import PDF.JS into a TypeScript project. I use the bindings > Definitely pdfjs-dist for pdfjs-dist installed via npm install @types/pdfjs-dist and npm install pdfjs-dist .
Problem
It seems like I am unable to TypeScript to compile my project. I use the source code copied directly from the tests for DefinitelyTyped. This is a simplified (only for removal) code that I am trying to compile (an exact copy of the test code from DefinitelyTyped also fails in the same way):
import { PDFJSStatic } from 'pdfjs-dist'; var PDFJS: PDFJSStatic; PDFJS.getDocument('helloworld.pdf').then(console.log);
TypeScript finds the type declaration module and considers that the PDFJSStatic import PDFJSStatic valid. He does not think that PDFJS ever initialized, but if I disable strict in tsconfig , the code compiles, but it compiles to:
"use strict"; exports.__esModule = true; var PDFJS; PDFJS.getDocument('helloworld.pdf').then(console.log);
Which is clearly not working. It does not compile the import statement into anything.
Question
How to import PDF.JS into a TypeScript project and compile it into a working Node.JS code through the declaration files in @types/pdfjs-dist ?
What i tried
I tried different import options, but to no avail. Switching to require also does not help.
I verified that the pdjs-dist and @types/pdfjs-dist dependencies are present, updated, and can be used directly from NodeJS (not TypeScript) programs.
I tried various values ββfor module in my tsconfig. Sometimes they change the generated code, but not one of them changes it to contain the necessary import.
I tried adding /// <reference path="../node_modules/@types/pdfjs-dist/index.d.ts" /> above the import line. This has not changed behavior.
Environment
tsc version 2.4.2, node 8.5 and npm 5.3. I have the following tsconfig.json in my project root:
{ "compilerOptions": { "allowJs":true, "rootDir": ".", "outDir": "dist", "moduleResolution": "node" }, "include": [ "src/**/*" ], "exclude": [ "**/*.spec.ts", "dist/**/*" ] }