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

Scribe.js does not work using Node.js on Windows #9

Open
Kuladeep561 opened this issue Oct 2, 2024 · 3 comments
Open

Scribe.js does not work using Node.js on Windows #9

Kuladeep561 opened this issue Oct 2, 2024 · 3 comments

Comments

@Kuladeep561
Copy link

Kuladeep561 commented Oct 2, 2024

Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:236:11)
at defaultLoad (node:internal/modules/esm/load:128:3)
at ModuleLoader.load (node:internal/modules/esm/loader:409:13)
at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:56)
at new ModuleJob (node:internal/modules/esm/module_job:65:26)
at #createModuleJob (node:internal/modules/esm/loader:303:17)
at ModuleLoader.getJobFromResolveResult (node:internal/modules/esm/loader:260:34)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:241:17)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ModuleLoader.import (node:internal/modules/esm/loader:328:23) {
code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}


{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "type": "module",
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.21.0",
    "scribe.js-ocr": "^0.2.8"
  }
}

#!/usr/bin/env node
// Run `node server.js path/to/image.jpg` to recognize text in an image.
import scribe from "scribe.js-ocr";

async function recognizeText(imgpath) {
  const res = await scribe.extractText([imgpath]);
  console.log(res);
  await scribe.terminate();
}

export { recognizeText };

import { recognizeText } from "./recognize.js"; // Adjust the path as necessary
import { pathToFileURL } from "url";

const imgpath = "C:/Users/kuk.idk/Downloads/test ocr.jpg";
const imgURL = pathToFileURL(imgpath).href;

if (imgURL) {
  recognizeText(imgURL).catch(console.error);
} else {
  console.error("Please provide an image path.");
}


@Balearica
Copy link
Contributor

Based on these messages there appears to be some issue specific to running with Node.js on Windows. I'll look into whether it's possible to get it running on Windows without undue effort.

@Balearica Balearica changed the title Unable to import the scribe.js from scribe.js-ocr into my node Scribe.js does not work using Node.js on Windows Oct 2, 2024
@Balearica
Copy link
Contributor

I investigated this, and it is currently not possible for us to support Node.js for Windows. The error messages you were encountering were caused by the fact that the web-worker package does not support Windows. I solved this error message by cutting out that dependency entirely. However, fixing this revealed multiple other errors, including issues stemming from dependency code we cannot feasibly change.

The most significant issue is that node-canvas has features that have been broken on Windows for some time, This dependency is critical, so this prevents any other progress we could make in other areas of the code from being useful. We can revisit if the node-canvas bug is ever patched.

The only thing I can recommend is running a Ubuntu terminal from Windows using WSL2. WSL2 integrates very well with Windows (once installed you just open a different command line), and you won't need to deal with any of Windows-specific issues (which appear to be very common across npm).

@Kuladeep561
Copy link
Author

Thanks for the quick resolution. I will do my best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants