Description
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.");
}