Registry / serialization / kuromoji

kuromoji

JSON →
library0.1.2jsnpmunverified

Kuromoji.js is a JavaScript implementation of a Japanese morphological analyzer, directly ported from the Java-based Kuromoji project. It provides functionality to tokenize Japanese text into its constituent words (morphemes) and extract detailed information such as part-of-speech tags, base forms, readings (pronunciation in Katakana), and surface forms. The package's current stable version is `0.1.2`, and its last known publication date was approximately eight years ago (around March 2018), indicating that the original project is largely abandoned or unmaintained. It primarily supports CommonJS modules for Node.js environments and global script inclusion for browsers, relying exclusively on callback-based asynchronous operations for dictionary loading. Due to its age, it lacks modern JavaScript features like ESM support, TypeScript definitions, and Promise-based APIs. Developers seeking these modern capabilities should consider using actively maintained forks such as `@patdx/kuromoji` or `code4fukui-es`, which offer updated architectures and features.

npm install kuromoji
INSTALL
IMPORT
SIG · KUROMOJI
K
kuromoji
serializationjavascriptv0.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.

kuromoji
var kuromoji = require('kuromoji');
import kuromoji from 'kuromoji';
The original `kuromoji` package uses CommonJS `require` syntax. It does not natively support ES Modules (`import`).
kuromoji.builder
var builder = require('kuromoji').builder;
import { builder } from 'kuromoji';
The `builder` function is the primary entry point to initialize the morphological analyzer. It is accessed via the `kuromoji` CommonJS export.
kuromoji (global)
<!-- In HTML --> <script src="url/to/kuromoji.js"></script> // In JavaScript kuromoji.builder(...)
const kuromoji = window.kuromoji;
In browser environments, `kuromoji.js` exposes a global `kuromoji` object after being loaded via a `<script>` tag. There's no need to manually assign it from `window`.

This example demonstrates how to initialize the Kuromoji.js tokenizer in Node.js, specifying the dictionary path, and then tokenize a Japanese sentence.

const path = require('path'); const kuromoji = require('kuromoji'); const dicPath = path.resolve(__dirname, 'node_modules/kuromoji/dict'); kuromoji.builder({ dicPath: dicPath }).build(function (err, tokenizer) { if (err) { console.error('Error building tokenizer:', err); return; } const sentence = "すもももももももものうち"; const tokens = tokenizer.tokenize(sentence); console.log(`Tokens for "${sentence}":`); tokens.forEach(token => { console.log(` - Surface: ${token.surface_form}, POS: ${token.pos}, Reading: ${token.reading}`); }); });
Debug
Known issues
gotchaThe original `kuromoji` package (takuyaa/kuromoji.js) is unmaintained since its last update approximately 8 years ago. It lacks modern features like ES Modules (ESM), TypeScript typings, and Promise-based APIs, relying solely on CommonJS and callbacks.
fix
For new projects or modern environments, consider using actively maintained forks such as `@patdx/kuromoji` or `code4fukui-es`, which offer ESM, Promises, and TypeScript support.
affects: 0.1.2
gotchaIncorrect `dicPath` configuration is a common source of errors, leading to `ENOENT` (file not found) or similar I/O issues during tokenizer initialization. The dictionary files are essential and must be accessible.
fix
Ensure `dicPath` points to the *exact* directory containing the gzipped dictionary files (e.g., `node_modules/kuromoji/dict` for npm installations in Node.js, or a correct CDN path for browsers). Use `path.resolve` in Node.js for robust path handling.
affects: >=0.1.0
deprecatedThe README suggests installing `kuromoji` via Bower for browser usage. Bower is a deprecated package manager and should no longer be used.
fix
For browser usage, either serve the `build/kuromoji.js` and `dict/*.dat.gz` files from your application or a CDN, or consider using a modern fork which typically provides better browser integration and bundling support via npm.
affects: >=0.1.0
Errors
Common errors & fixes
Uncaught ReferenceError: kuromoji is not defined
The `kuromoji.js` script was not loaded in the HTML before attempting to use the `kuromoji` global object in the browser, or the CommonJS `require` statement was not executed in Node.js.
fix
In a browser, ensure `<script src="url/to/kuromoji.js"></script>` appears before your script that uses `kuromoji`. In Node.js, ensure `var kuromoji = require('kuromoji');` is at the top of your module.
Error: ENOENT: no such file or directory, open 'path/to/dictionary/dir/base.dat.gz'
The `dicPath` provided to `kuromoji.builder()` does not correctly point to the directory containing the Kuromoji dictionary files.
fix
Verify that `dicPath` is an absolute or correct relative path to where the `dict` folder (containing `base.dat.gz`, `tid.dat.gz`, etc.) is located. For npm installations, this is often `path.resolve(__dirname, 'node_modules/kuromoji/dict')` in Node.js.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
kuromoji — npm install kuromoji · libregistry