Registry / ai-ml / lindera-wasm-cjk-bundler

lindera-wasm-cjk-bundler

JSON →
library2.3.4jsnpmunverified

Lindera WASM CJK Bundler is a JavaScript package providing morphological analysis for Chinese, Japanese, and Korean languages, optimized for environments using module bundlers. It leverages WebAssembly (WASM) for efficient tokenization, integrating IPADIC (Japanese), ko-dic (Korean), and CC-CEDICT (Chinese) dictionaries directly into the bundle. The package is currently at version 2.3.4, with the main Lindera project actively releasing new major versions (e.g., v3.x) that introduce significant architectural changes, including new NAPI-RS Node.js bindings and updated package naming conventions. Lindera's core differentiator is its multilingual CJK support via WASM, offering performance benefits in browser and bundler-driven Node.js environments compared to pure JavaScript or server-side solutions, with a focus on embedded dictionaries for ease of use. It aims for ease of deployment in complex modern JavaScript ecosystems requiring bundling.

npm install lindera-wasm-cjk-bundler
INSTALL
IMPORT
SIG · LINDERA-WASM-CJK-B
L
lindera-wasm-cjk-bundler
ai-mljavascriptv2.3.4
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.

__wbg_init
import __wbg_init from 'lindera-wasm-cjk-bundler';
import { __wbg_init } from 'lindera-wasm-cjk-bundler';
This is the default export and *must* be awaited to initialize the WebAssembly module before any other functions are called.
TokenizerBuilder
import { TokenizerBuilder } from 'lindera-wasm-cjk-bundler';
import TokenizerBuilder from 'lindera-wasm-cjk-bundler';
The TokenizerBuilder class is a named export used to configure and create tokenizer instances. It should not be imported as a default export.
Token
import type { Token } from 'lindera-wasm-cjk-bundler';
The 'Token' type defines the structure of the morphological analysis results, including properties like 'surface' and 'details'. This is primarily for TypeScript users to ensure type safety.

Initializes the Lindera WASM CJK tokenizer, demonstrates setting the embedded CJK dictionary, tokenizing a multi-language CJK string, and logging the analysis results.

import __wbg_init, { TokenizerBuilder, Token } from 'lindera-wasm-cjk-bundler'; async function main() { // Initialize the WebAssembly module. This must be called before using other functions. await __wbg_init(); // Create a new TokenizerBuilder instance. const builder = new TokenizerBuilder(); // Set the dictionary to be used. "embedded://cjk" specifies the bundled CJK dictionary. builder.setDictionary("embedded://cjk"); // Set the tokenization mode. "normal" is a common choice. builder.setMode("normal"); // Build the tokenizer instance. const tokenizer = builder.build(); // Text for morphological analysis (Japanese, Korean, Chinese examples). const text = "すもももももももものうち。안녕하세요.我爱北京天安门。"; // Perform tokenization. const tokens: Token[] = tokenizer.tokenize(text); console.log(`Tokens for "${text}":`); tokens.forEach(token => { // Log the surface form and detailed analysis of each token. console.log(`- ${token.surface}: ${token.details.join(", ")}`); }); // Example with another CJK language: Korean const koreanText = "한국어를 공부합니다."; const koreanTokens: Token[] = tokenizer.tokenize(koreanText); console.log(`\nTokens for "${koreanText}":`); koreanTokens.forEach(token => { console.log(`- ${token.surface}: ${token.details.join(", ")}`); }); // Example with another CJK language: Chinese const chineseText = "上海东方明珠广播电视塔"; const chineseTokens: Token[] = tokenizer.tokenize(chineseText); console.log(`\nTokens for "${chineseText}":`); chineseTokens.forEach(token => { console.log(`- ${token.surface}: ${token.details.join(", ")}`); }); } main().catch(console.error);
Debug
Known issues
breakingWith the release of v3.0.0, the Lindera project introduced significant package naming changes. The previous `lindera-wasm-*` packages that targeted Node.js directly were removed. Users should now explicitly use `lindera-wasm-*-nodejs` for direct Node.js environments or `lindera-wasm-*-bundler` (this package) with a bundler configured for Node.js. Older import paths will no longer resolve.
fix
Migrate to `lindera-wasm-cjk-nodejs` for direct Node.js environments or use this `lindera-wasm-cjk-bundler` package with a module bundler (like Webpack, Rollup, esbuild) that targets Node.js. Update import paths and package names in your `package.json` accordingly.
affects: <3.0.0
gotchaThe core WebAssembly module requires asynchronous initialization via the default export `__wbg_init()` before any other functions (like `TokenizerBuilder`) can be used. Forgetting to `await` this function or call it at all will lead to runtime errors.
fix
Always call and `await` the `__wbg_init()` function at the start of your application's execution flow before instantiating `TokenizerBuilder` or other Lindera WASM components.
affects: >=1.0.0
gotchaThis `lindera-wasm-cjk-bundler` package is specifically optimized for use with module bundlers (e.g., Webpack, Rollup, esbuild) for both browser and Node.js targets. Attempting to use it directly in a browser without bundling, or in a Node.js environment without a bundler, might lead to unexpected import resolution issues or runtime errors depending on your Node.js version and module system configuration.
fix
When targeting web browsers, ensure your project utilizes a module bundler. When targeting Node.js, for direct usage, consider `lindera-wasm-cjk-nodejs`. If using this `bundler` variant for Node.js, ensure your bundler is configured to output Node.js-compatible modules.
affects: >=2.0.0
gotchaWhen using `lindera-wasm-cjk-bundler`, the dictionary must be specified as `"embedded://cjk"` to correctly load the pre-bundled CJK dictionaries. Using other dictionary identifiers (e.g., `"embedded://ipadic"`) or attempting to load external dictionaries will fail, as this package is configured with a specific CJK dictionary set.
fix
Ensure `builder.setDictionary("embedded://cjk")` is used when utilizing `lindera-wasm-cjk-bundler` to leverage its integrated dictionaries. For other specific dictionary needs, use their corresponding `lindera-wasm-*` packages (e.g., `lindera-wasm-ipadic-bundler`).
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'TokenizerBuilder')
The WebAssembly module was not initialized or not properly awaited, or the TokenizerBuilder symbol was imported incorrectly.
fix
Ensure you `await __wbg_init();` before attempting to use `TokenizerBuilder`. Also, verify `TokenizerBuilder` is imported as a named export: `import { TokenizerBuilder } from 'lindera-wasm-cjk-bundler';`.
SyntaxError: require() of ES Module lindera-wasm-cjk-bundler from ... not supported.
Attempting to use CommonJS `require()` syntax with this ES Module package, which is designed for bundlers or native ESM environments.
fix
Use ES Module `import` syntax (`import __wbg_init, { TokenizerBuilder } from 'lindera-wasm-cjk-bundler';`) in your project and ensure your environment (e.g., Node.js with `"type": "module"` in `package.json`, or a bundler) correctly handles ESM.
Error: No such dictionary: embedded://cjk
The specified dictionary name does not match the bundled dictionary or there's an issue with the dictionary path.
fix
For `lindera-wasm-cjk-bundler`, always use `builder.setDictionary("embedded://cjk")`. If you intend to use a specific dictionary like IPADIC, you should use `lindera-wasm-ipadic-bundler` and `builder.setDictionary("embedded://ipadic")`.
Upgrade
Version history
2.3.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
lindera-wasm-cjk-bundler — npm install lindera-wasm-cjk-bundler · libregistry