How to use Tesseract.js in a React app

允我心安 提交于 2019-12-05 07:12:00

I had the same issue, and then I had to dig a bit to have it working using the CDN.

Here is what I did, I hope this can help a bit as a workaround:

  1. add <script src='https://cdn.rawgit.com/naptha/tesseract.js/1.0.10/dist/tesseract.js'></script> in index.html inside <head></head>
  2. add var Tesseract = window.Tesseract; in App.js

Reference : https://github.com/naptha/tesseract.js/issues/134

Try this one:)

1) Install the below node module npm i -S tesseract.ts tesseract.js

2) import Tesseract from 'tesseract.ts'

you are ready to go....

Johan Buys

I just made a wrapper based on the Typescript Wrapper, using it with next.js (React) and its working.

TesseractWrapper.js

if (typeof window !== 'undefined') {
  const _instance = window ? require("tesseract.js/dist/tesseract") : require('tesseract.js');
  exports.Tesseract = _instance;
}

then I just

import { Tesseract } from '../../lib/TesseractWrapper';

I know it has been a long time for this question, right now tesseract.js@1.0.16 has fixed the issue, and it can be used with any frameworks like react, vue and angular with no more issues.

P.S. I am one of the contributors for tesseract.js right now, feel free to let me know if you have any issues/requirements. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!