{"id":11219,"library":"kuromoji","title":"Kuromoji.js","description":"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.","status":"abandoned","version":"0.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/takuyaa/kuromoji.js","tags":["javascript","japanese","morphological analyzer","nlp","pos","pos tagger","tokenizer"],"install":[{"cmd":"npm install kuromoji","lang":"bash","label":"npm"},{"cmd":"yarn add kuromoji","lang":"bash","label":"yarn"},{"cmd":"pnpm add kuromoji","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The original `kuromoji` package uses CommonJS `require` syntax. It does not natively support ES Modules (`import`).","wrong":"import kuromoji from 'kuromoji';","symbol":"kuromoji","correct":"var kuromoji = require('kuromoji');"},{"note":"The `builder` function is the primary entry point to initialize the morphological analyzer. It is accessed via the `kuromoji` CommonJS export.","wrong":"import { builder } from 'kuromoji';","symbol":"kuromoji.builder","correct":"var builder = require('kuromoji').builder;"},{"note":"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`.","wrong":"const kuromoji = window.kuromoji;","symbol":"kuromoji (global)","correct":"<!-- In HTML --> <script src=\"url/to/kuromoji.js\"></script>\n// In JavaScript\nkuromoji.builder(...)"}],"quickstart":{"code":"const path = require('path');\nconst kuromoji = require('kuromoji');\n\nconst dicPath = path.resolve(__dirname, 'node_modules/kuromoji/dict');\n\nkuromoji.builder({ dicPath: dicPath }).build(function (err, tokenizer) {\n    if (err) {\n        console.error('Error building tokenizer:', err);\n        return;\n    }\n    const sentence = \"すもももももももものうち\";\n    const tokens = tokenizer.tokenize(sentence);\n    console.log(`Tokens for \"${sentence}\":`);\n    tokens.forEach(token => {\n        console.log(`  - Surface: ${token.surface_form}, POS: ${token.pos}, Reading: ${token.reading}`);\n    });\n});","lang":"javascript","description":"This example demonstrates how to initialize the Kuromoji.js tokenizer in Node.js, specifying the dictionary path, and then tokenize a Japanese sentence."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":"0.1.2"},{"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.","message":"Incorrect `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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The README suggests installing `kuromoji` via Bower for browser usage. Bower is a deprecated package manager and should no longer be used.","severity":"deprecated","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"Uncaught ReferenceError: kuromoji is not defined"},{"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.","cause":"The `dicPath` provided to `kuromoji.builder()` does not correctly point to the directory containing the Kuromoji dictionary files.","error":"Error: ENOENT: no such file or directory, open 'path/to/dictionary/dir/base.dat.gz'"}],"ecosystem":"npm"}