6
votes

I'm trying to import Tesseract into Angular2 (TypeScript). I can see it saved into the node_modules folder but when using

import { Tesseract } from '@types/tesseract.js';

it says:

[ts] Module '"c:/Users/black/Projects/projectCLI/tess/node_modules/@types/tesseract.js/index"' has no exported member 'Tesseract'.

In the index.d.ts file there is a namespace called Tesseract.

Is there some other way to import this or are we looking at this the wrong way?

I used npm install --save-dev @types/tesseract.js to install typescript Tesseract.

If there are any demo tutorials using tesseract can you please link them here?

thanks, in advance, for your help.

1
@types just has type declarations. Do you have the actual javascript module? you have to import from there - Suraj Rao
Do you use Angular 2 with Angular CLI, Webpack or SystemJS ? - Monicka
Suraj: Could you please give an example of the import syntax? It is already visible in node_modules inside @types. Thanks the first syntax in question is what we are trying at the moment - The BrownBatman
@SimonaMi We use Angular 2 with AngularCLI, Webpack. - The BrownBatman
try import * as T from Tesseract - Suraj Rao

1 Answers

12
votes

You need to install the actual javascript module:
npm install tesseract.js --save

Also install @types declarations:
npm install @types/tesseract.js --save-dev

Finally do the folowing to import:
import * as Tesseract from 'tesseract.js'

To use the library check here

The @types command saves this type declaration file.
This is a namespace and all the contents of the actual module are declared within.When you do import * as aliasname from tessreact.js, you can use all the functions within the namespace as aliasname.functionname. Example is the test file for the same type declaration file.