1

I'm new to TypeScript and I'm trying to use a regular library that was written in vanilla JavaScript but I'm getting an error when trying to execute the code.

index.ts:

import OpenSubtitles from 'opensubtitles-api';
new OpenSubtitles;

when trying to node dist/index.js:

new opensubtitles_api_1.default;

TypeError: opensubtitles_api_1.default is not a constructor

edit:

It has nothing to do with the duplicated thread as this one is related to TypeScript and not ES6 itself, and the other thread is talking about old JavaScript syntax compatibility with ES6 but the library I'm trying to link is written in ES6 (using classes and so on, so that is not a duplicated thread).

Community
  • 1
  • 1
yugosonegi
  • 65
  • 5
  • how are you exporting OpenSubtitles – Vipin Kumar Dec 17 '17 at 04:05
  • `yarn add opensubtitles-api` - https://www.npmjs.com/package/opensubtitles-api – yugosonegi Dec 17 '17 at 04:16
  • 1
    Possible duplicate of [New es6 syntax for importing commonjs / amd modules i.e. \`import foo = require('foo')\`](https://stackoverflow.com/questions/29596714/new-es6-syntax-for-importing-commonjs-amd-modules-i-e-import-foo-require) – AuxTaco Dec 17 '17 at 04:18
  • I don't think that it's duplicated and I edited the question to tell why. – yugosonegi Dec 17 '17 at 12:52
  • did you try `new OpenSubtitles()` – Ayush Gupta Dec 17 '17 at 13:03
  • It's still the same problem. – yugosonegi Dec 17 '17 at 13:46
  • 1
    Although the library you linked to uses some ES6 features, it still does not `export` anything using ES6 modules and, hence, the error. This, in fact, makes it a kind-of duplicate of [*"New es6 syntax for importing commonjs / amd modules i.e. `import foo = require('foo')`"*](/q/29596714). – altocumulus Dec 17 '17 at 15:55

0 Answers0