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> {
|
async function getOcrWorker(): Promise<Tesseract.Worker> {
|
||||||
if (sharedWorker) return sharedWorker;
|
if (sharedWorker) return sharedWorker;
|
||||||
if (!sharedWorkerPromise) {
|
if (!sharedWorkerPromise) {
|
||||||
let workerPath: string | undefined;
|
// Resolve filesystem path at runtime avoiding Webpack's numeric module ID substitution
|
||||||
try {
|
const candidatePath = path.join(
|
||||||
workerPath = require.resolve('tesseract.js/src/worker-script/node/index.js');
|
process.cwd(),
|
||||||
} catch {}
|
'node_modules/tesseract.js/src/worker-script/node/index.js'
|
||||||
|
);
|
||||||
const options: Record<string, unknown> = {};
|
const options: Record<string, unknown> = {};
|
||||||
if (workerPath) {
|
try {
|
||||||
options.workerPath = workerPath;
|
if (require('fs').existsSync(candidatePath)) {
|
||||||
}
|
options.workerPath = candidatePath;
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
sharedWorkerPromise = createWorker('eng', 1, options)
|
sharedWorkerPromise = createWorker('eng', 1, options)
|
||||||
.then((w) => {
|
.then((w) => {
|
||||||
|
|||||||
Reference in new issue
Block a user