tesseract.js
tesseract.js copied to clipboard
Cannot access ambient const enums when the '--isolatedModules' flag is provided
Describe the bug
This error occurs when attempting to use tesseract.js typescript enums which are defined as const enum. This prevents these enums from being used in popular frameworks such as create-react-app.
Specifically: OEM and PSM enums.
To Reproduce Steps to reproduce the behavior:
- Set up a create-react-app project and install tesseract.js.
- Attempt to initialize a worker with an OEM mode.
Expected behavior Code compiles.
Screenshots

Desktop (please complete the following information): Inapplicable
Smartphone (please complete the following information): Inapplicable
Additional context
Possible solution is to remove const from these enums.
I am aware of simply using integers because these are const enums. However, since this library is providing an enum definition anyway, referring to enums by name should be preferred over magic numbers.
Can you share the full example code to reproduce this issue?
Hello.
It has been almost 2 years but this problem still persists. Reported reproduction steps look good to me but if you still need an example, I have created a project using react example from readme and added typescript. My reproduction example.
The only change I have made to the template code is adding await worker.setParameters({ tessedit_pageseg_mode: PSM.AUTO, }) to demonstrate const enum issue.
Typescript has an explanation on the topic.
For the time being, I removed const from those two enums and got no problems so far.
I'm not the most knowledgeable regarding typescript, however see no reason not to remove const given the discussion above. The potential downsides with regards to inlining seems negligible. Will include in next release.