Registry / ai-ml / tesseract.js-core

tesseract.js-core

JSON →
library6.1.2jsnpmunverified

tesseract.js-core is the foundational WebAssembly (WASM) module that powers the higher-level tesseract.js OCR library. It compiles the original Tesseract C++ engine to JavaScript and WASM using Emscripten, enabling Optical Character Recognition directly in browser and Node.js environments. The current stable version is `7.0.0` as of December 2025. This package provides the low-level API for interacting with the Tesseract engine, offering optimized builds like 'Relaxed SIMD' for performance on supported hardware and 'LSTM-only' builds for reduced size when only the modern LSTM OCR engine is needed. It typically releases new major versions to incorporate updates from the upstream Tesseract C++ project and Emscripten. Key differentiators include its pure JavaScript/WASM implementation, enabling client-side OCR, and direct access to Tesseract's core functionality, which is crucial for custom integrations or highly performance-sensitive applications that bypass the abstractions of `tesseract.js`.

npm install tesseract.js-core
INSTALL
IMPORT
SIG · TESSERACT.JS-CORE
T
tesseract.js-core
ai-mljavascriptv6.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TesseractCore
import TesseractCoreInit from 'tesseract.js-core/tesseract-core';
import { TesseractCore } from 'tesseract.js-core'; // Incorrect named import for factory function
The package exports a default factory function (e.g., `TesseractCoreInit`) from specific build paths, not the package root. You need to call this function to get the WASM module instance.
TesseractCoreSIMD
import TesseractCoreSIMDInit from 'tesseract.js-core/tesseract-core-simd';
const TesseractCoreSIMD = require('tesseract.js-core/tesseract-core-simd'); // Await is needed for the factory function
For builds optimized with WebAssembly SIMD instructions, import from the `-simd` path. Remember to await the factory function call to get the module.
TesseractCoreLSTM
import TesseractCoreLSTMInit from 'tesseract.js-core/tesseract-core-lstm';
import TesseractCoreLSTM from 'tesseract.js-core/tesseract-core-lstm.wasm'; // Import the JS wrapper, not the raw WASM
For smaller builds supporting only the LSTM recognition engine, use the `-lstm` path. Always import the `.js` wrapper file, which handles loading the corresponding `.wasm`.

Demonstrates how to load the `tesseract.js-core` WebAssembly module, initialize the Tesseract API, set an image buffer, perform OCR, and retrieve the recognized text using low-level methods. This example simulates a Node.js environment.

import { readFileSync } from 'fs'; import TesseractCoreInit from 'tesseract.js-core/tesseract-core'; const runOcr = async (imagePath) => { console.log('Loading TesseractCore module...'); // The factory function returns a Promise that resolves to the Emscripten module const TesseractCore = await TesseractCoreInit(); console.log('TesseractCore module loaded. Initializing...'); // This is a minimal example showing low-level API interaction. // In a real application, consider using tesseract.js for a higher-level API. const core = new TesseractCore.TesseractApi(); core.Init(process.env.LANG_PATH || '/usr/share/tessdata', 'eng'); // Initialize with language data const imageBuffer = readFileSync(imagePath); // Assuming imageBuffer is a PNG or JPG and Tesseract can handle its format directly // In a browser, you might pass a Canvas/ImageData object core.SetImage(imageBuffer, imageBuffer.width, imageBuffer.height, 4, imageBuffer.width * 4); core.Recognize(); const text = core.GetUTF8Text(); console.log('Recognized Text:', text); core.End(); TesseractCore.destroy(core); // Clean up Emscripten instance }; // Example usage: Assumes 'image.png' exists in the same directory // For a real scenario, replace 'image.png' with your actual image path. // process.env.LANG_PATH should point to directory containing .traineddata files. runOcr('image.png').catch(console.error);
Debug
Known issues
breakingMajor versions of `tesseract.js-core` must match the major versions of `tesseract.js` they are used with. For example, `tesseract.js-core v7` should only be used with `tesseract.js v7`. Mismatched versions will likely lead to runtime errors or undefined behavior.
fix
Always install `tesseract.js-core` and `tesseract.js` with matching major version numbers. Refer to the `tesseract.js` documentation for compatible core versions.
affects: >=4.0.0
breakingThe WASM module name changed from `TesseractCoreWASM` to `TesseractCore` in `v4.0.4`. Direct integrations relying on the specific global name or export might be affected.
fix
Update references to the core module to use `TesseractCore` instead of `TesseractCoreWASM`.
affects: >=4.0.4
gotchaThe `v7.0.0` release introduced a new 'Relaxed SIMD' build, which utilizes WebAssembly Relaxed SIMD dot-product instructions for significant performance improvements (~1.6x faster on supported hardware). However, this feature is not universally supported across all browsers and runtimes.
fix
If using the 'Relaxed SIMD' build and encountering `WebAssembly.compile()` errors, ensure the target environment supports `wf-wasm-simd-relaxed`. Fall back to the standard SIMD build (`tesseract-core-simd`) or the non-SIMD build (`tesseract-core`) if compatibility issues arise.
affects: >=7.0.0
gotchaStarting with `v5.0.0`, 'LSTM-only' builds were introduced. These builds are approximately 0.75MB smaller but exclusively support the Tesseract LSTM model and do not include support for the older Tesseract Legacy engine.
fix
If you require the Tesseract Legacy engine, avoid using the `*-lstm` specific builds. Most modern use cases are fine with LSTM-only builds, as LSTM is the default and generally more accurate engine.
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: TesseractCore is not a function
Attempting to use the imported module directly without calling its factory function. Emscripten modules typically export a factory function that must be awaited to get the actual module instance.
fix
Ensure you call the imported factory function and `await` its result: `const TesseractCore = await TesseractCoreInit();`
Error: Cannot find module 'tesseract.js-core' or 'tesseract.js-core/tesseract-core'
Incorrect import path for the specific build or general package. `tesseract.js-core` provides multiple build variants (e.g., `tesseract-core`, `tesseract-core-simd`, `tesseract-core-lstm`) each with its own entry point.
fix
Verify the exact path for the desired build variant (e.g., `import TesseractCoreInit from 'tesseract.js-core/tesseract-core';`). Check the `node_modules/tesseract.js-core` directory for available `.js` files.
WebAssembly.compile(): Wasm code is not valid: Invalid opcode
The WebAssembly module contains instructions (like Relaxed SIMD) not supported by the current browser or Node.js runtime environment.
fix
If using a `-simd` or `-relaxed-simd` build, try switching to a less optimized build (e.g., `tesseract-core` or `tesseract-core-lstm`) that uses a more widely compatible WebAssembly feature set. Ensure your environment is up-to-date.
Failed to load /tesseract-core.wasm: 404 Not Found
In browser environments, the `.wasm` file (and potentially `.traineddata` files) are not correctly served from the expected path by the web server.
fix
Configure your web server to serve `.wasm` (and `.traineddata`) files from the root or the path where the `tesseract-core.js` wrapper expects them. Often, Emscripten modules expect the `.wasm` file to be co-located with the `.js` glue code or served from a configurable `locateFile` path.
Upgrade
Version history
6.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
tesseract.js-core — npm install tesseract.js-core · libregistry