Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCR In Electron-vite using Tesseract via node-native-ocr #223

Open
arvinjarvin opened this issue Jul 19, 2024 · 1 comment
Open

OCR In Electron-vite using Tesseract via node-native-ocr #223

arvinjarvin opened this issue Jul 19, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@arvinjarvin
Copy link

Trying to use OCR from frontend using node-native-ocr package

The output is just
recognize isn't exported from node-native-ocr
(in the dev console)

Also tried to add this to the optimizeDeps exclusions array in the electron.vite.config.ts

Still no luck

I note that electron-vite 'doesn't support nodeIntegration' - I have also tried to plugin using commonjsExternals, but now it says

require is not defined

in the frontend.

This will be an interesting one...

@arvinjarvin arvinjarvin added the help wanted Extra attention is needed label Jul 19, 2024
@arvinjarvin
Copy link
Author

arvinjarvin commented Jul 19, 2024

Content of electron.vite.config.ts

import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin, bytecodePlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'
import commonjsExternals from 'vite-plugin-commonjs-externals'

let externals = ['node-native-ocr', 'babel-runtime', 'node-addon-api', 'prebuild-install']

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin(), bytecodePlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin(), bytecodePlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src')
      }
    },
    optimizeDeps: {
      exclude: externals
    },
    plugins: [react(), commonjsExternals({ externals })]
  }
})

Content of App.tsx relevant section:

recognize(my_img_here, (err: any, text: any)) => {
            if (err) {
              console.error(err)
            } else {
              console.log(text)
            }
          })

May have misplaced some brackets during transfer as I changed to my_img_here however rest assured the problem is not syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant