Resolve workerPath using path.join to avoid Webpack numeric module ID substitution
This commit is contained in:
1 parent
739cbce042
commit
2eb283b9ec
1 file changed
+10
-8
+10
-8
@@ -26,15 +26,17 @@ let sharedWorkerPromise: Promise<Tesseract.Worker> | null = null;
|
||||
async function getOcrWorker(): Promise<Tesseract.Worker> {
|
||||
if (sharedWorker) return sharedWorker;
|
||||
if (!sharedWorkerPromise) {
|
||||
let workerPath: string | undefined;
|
||||
try {
|
||||
workerPath = require.resolve('tesseract.js/src/worker-script/node/index.js');
|
||||
} catch {}
|
||||
|
||||
// Resolve filesystem path at runtime avoiding Webpack's numeric module ID substitution
|
||||
const candidatePath = path.join(
|
||||
process.cwd(),
|
||||
'node_modules/tesseract.js/src/worker-script/node/index.js'
|
||||
);
|
||||
const options: Record<string, unknown> = {};
|
||||
if (workerPath) {
|
||||
options.workerPath = workerPath;
|
||||
}
|
||||
try {
|
||||
if (require('fs').existsSync(candidatePath)) {
|
||||
options.workerPath = candidatePath;
|
||||
}
|
||||
} catch {}
|
||||
|
||||
sharedWorkerPromise = createWorker('eng', 1, options)
|
||||
.then((w) => {
|
||||
|
||||
Reference in new issue
Block a user