I asked for this error on GitHub as an issue @laurent22 said that it's more of a support request so I'm asking here for support or any resources that can help.
I'm trying to develop a basic Joplin Plugin which simply takes an image and generate the OCRed text using tesseractjs
This is my code:
import joplin from 'api';
import { ToolbarButtonLocation } from 'api/types';
const { createWorker } = require("tesseract.js");
const worker = createWorker();
joplin.plugins.register({
onStart: async function() {
...
await joplin.views.panels.onMessage(view, async (message) => {
console.log('Plugin: Recieved Message: ', message);
await worker.load();
await worker.loadLanguage('eng');
await worker.initialize('eng');
const { data: { text } } = await worker.recognize(message.hash);
console.log('Plugin: Reconized Text: ', text);
await worker.terminate();
});
...
},
});
I tried the code of tesseractjs in a separate script using Node and it works fine so it's not a tesseract issue but when I add the script to the plugin it throws the following error:

@roman-r-m replied with the following:
"
Yep, tried that too.
You need to see what createWorker does: it forks a new node process passing it a certain script.
Now, you have 2 issues there:
- That script is not bundled with your plugin - this you can solve by fiddling with webpack config (at least that's how I did it)
- You need to provide the correct script to that fork method. However due to how Joplin executes plugin scripts this was not trivial, don't remember in details why exactly."
but I can't figure out what should I do? can you recommend me any resources to read more about the problem?
Why use a worker anyway? The plugin already runs in a separate process.
That's how tesseract.js works
If this is for GSoC then maybe you should start with something easier? This is by no means a basic plugin.
Otherwise best resources are tesseract.js and Joplin sources.
I've outlined what's required to get it to work (I think, might be completely wrong).
UPD
Just remembered, I think there was also webassembly involved for extra fun.
I'm applying for the project in GSoC but this is just a very basic try to get familiar with the challenges that I may face so I can write a better proposal for the project
@roman_r_m
I'm sorry for asking so many questions, I appreciate your time in responding to whatever you can. What do you mean by that script? do you mean the tesseract core script?
I tried to provide the absolute path of tesseract, worker, and tesseract core
const {createWorker} = require("/home/aashrafh/Desktop/ocr-joplin/node_modules/tesseract.js/dist/tesseract.min.js");
const path = '';
const worker = createWorker({
workerPath: `${path}/node_modules/tesseract.js/dist/worker.min.js`,
corePath: `${path}/node_modules/tesseract.js-core/tesseract-core.wasm.js`,
logger: m => console.log("Tesseract: ", m),
})
It does some progress before throws a new error
Am I on the right way? and any suggestions about that error?
I don't remember in details, sorry. The script I meant is the one that tesseract.js passes to the forked process. You'll have to read the source code to find it.
The error you got - I do not recall ever seeing it.
I remember there was also an issue within tesseract.js itself which made it fail even with the correct path provided. I think it may be this one Worker Script Path has 'http:/localhost' prepended, causing MODULE_NOT_FOUND error · Issue #474 · naptha/tesseract.js · GitHub
One more thing to note is if you want to build a proper plugin not just for dev experiments, then you can't access node_modules because it won't be packaged into the .jpl file.