tesseract.js
tesseract.js copied to clipboard
Cannot find module - Electron
Describe the bug When attempting to use TesserractJS in electron I get the following error.
internal/modules/cjs/loader.js:895
throw err;
^
Error: Cannot find module 'C:\dev\poe\worker-script\node\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:892:15)
at Module._load (internal/modules/cjs/loader.js:737:27)
at Function.f._load (electron/js2c/asar_bundle.js:5:12913)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
To Reproduce
import robotjs from 'robotjs'
import { logger } from '@/main/logger'
// eslint-disable-next-line @typescript-eslint/no-var-requires
import Jimp from 'jimp/es'
import { createWorker } from 'tesseract.js'
import path from 'path'
export const lookupCurio = async () => {
logger.debug(__dirname)
const mouse = robotjs.getMousePos()
const size = {
x: 200,
y: 50
}
const screen = robotjs.screen.capture(mouse.x - (size.x / 2), mouse.y - (size.y / 2), size.x, size.y)
// eslint-disable-next-line no-new
new Jimp({
data: screen.image,
width: size.x,
height: size.y
}, (err: any, image: any) => {
if (err) {
console.log('jimp error: ', err)
} else {
image.write('test.png', async (writeErr: any) => {
if (writeErr) {
console.log('Jimp write err', writeErr)
}
const worker = createWorker({
logger: m => console.log(m),
dataPath: 'lang-data',
cachePath: path.join(__dirname, 'lang-data')
})
await worker.load()
await worker.loadLanguage('eng')
await worker.initialize('eng')
const { data: { text } } = await worker.recognize('test.png')
console.log(text)
await worker.terminate()
})
}
})
}