{"id":13469,"library":"lindera-wasm-unidic-bundler","title":"Lindera WASM UniDic Bundler","description":"Lindera WASM UniDic Bundler is a JavaScript package providing a WebAssembly-based Japanese morphological analyzer, specifically pre-bundled with the UniDic dictionary. It is optimized for use within environments where JavaScript bundlers (like Webpack, Rollup, Parcel) are employed, typically targeting web browsers. The library provides capabilities for tokenization and detailed linguistic analysis of Japanese text. The current stable major version is `3.x.x`, with `3.0.5` being a recent release at the time of writing. Releases are made on an as-needed basis, often driven by Rust dependency updates or bug fixes. A key differentiator within the Lindera ecosystem is its explicit targeting of different environments (web, Node.js, bundler) and its flexibility in dictionary choice, making this package suitable for web applications requiring Japanese text processing.","status":"active","version":"2.3.4","language":"javascript","source_language":"en","source_url":"https://github.com/lindera/lindera","tags":["javascript","morphological","analysis","library","wasm","webassembly","typescript"],"install":[{"cmd":"npm install lindera-wasm-unidic-bundler","lang":"bash","label":"npm"},{"cmd":"yarn add lindera-wasm-unidic-bundler","lang":"bash","label":"yarn"},{"cmd":"pnpm add lindera-wasm-unidic-bundler","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The WASM initialization function `init` is typically a default export and must be called asynchronously before using other library features.","wrong":"import { init } from 'lindera-wasm-unidic-bundler';","symbol":"init","correct":"import init from 'lindera-wasm-unidic-bundler';"},{"note":"This package is designed for ESM environments and bundlers. CommonJS `require` is not supported for `3.x.x` versions. `TokenizerBuilder` is a named export.","wrong":"const { TokenizerBuilder } = require('lindera-wasm-unidic-bundler');","symbol":"TokenizerBuilder","correct":"import { TokenizerBuilder } from 'lindera-wasm-unidic-bundler';"},{"note":"The `Token` type definition for processed output is a named export. It is available for TypeScript users.","wrong":"import type Token from 'lindera-wasm-unidic-bundler';","symbol":"Token","correct":"import { Token } from 'lindera-wasm-unidic-bundler';"}],"quickstart":{"code":"import init, { TokenizerBuilder } from 'lindera-wasm-unidic-bundler';\n\n// This example assumes a bundler setup for browser execution.\n// The `init` function loads the WASM module and its associated dictionary.\n\nasync function main() {\n    try {\n        await init(); // Initialize the WebAssembly module\n\n        const builder = new TokenizerBuilder();\n        // Specify the embedded UniDic dictionary for this package\n        builder.setDictionary(\"embedded://unidic\");\n        builder.setMode(\"normal\"); // Other modes: \"decompose\", \"search\"\n        const tokenizer = builder.build();\n\n        const text = \"東京スカイツリーの高さは634mです。\"; // Example Japanese text\n        const tokens = tokenizer.tokenize(text);\n\n        console.log(`Tokenizing: \"${text}\"`);\n        tokens.forEach(token => {\n            // Each token has 'surface' (the word) and 'details' (linguistic information)\n            console.log(`${token.surface}: ${token.details.join(\", \")}`);\n        });\n    } catch (error) {\n        console.error(\"Failed to initialize or tokenize:\", error);\n    }\n}\n\nmain();","lang":"typescript","description":"Demonstrates how to initialize the WASM module and perform basic Japanese morphological analysis using the UniDic dictionary."},"warnings":[{"fix":"Migrate to the appropriate package (e.g., `lindera-wasm-unidic-web` for direct browser usage without a bundler, `lindera-wasm-unidic-nodejs` for pure Node.js environments leveraging NAPI-RS bindings, or `lindera-wasm-unidic-bundler` for bundler-processed web apps).","message":"Version 3.0.0 introduced significant changes in package naming and target environments. Separate packages like `lindera-wasm-unidic-web`, `lindera-wasm-unidic-nodejs`, and `lindera-wasm-unidic-bundler` were established. Ensure you select the correct package for your target environment (e.g., `*-bundler` for browser applications processed by a bundler).","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always call `await init();` at the start of your application logic that depends on Lindera.","message":"The WASM module's initialization function (`init()`) is asynchronous and must be awaited before any other library functions (like `TokenizerBuilder`) can be used. Forgetting to await it will lead to runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure `builder.setDictionary(\"embedded://unidic\");` is called when configuring the tokenizer for this package.","message":"This specific package (`lindera-wasm-unidic-bundler`) includes the UniDic dictionary. When initializing the tokenizer, you must explicitly set the dictionary to `\"embedded://unidic\"` via `builder.setDictionary()`. Using `\"embedded://ipadic\"` or other dictionary identifiers will cause a runtime error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For pure Node.js applications, use `lindera-wasm-unidic-nodejs` instead of `lindera-wasm-unidic-bundler`.","message":"For Node.js environments, `v3.0.0` and later versions now provide dedicated `lindera-wasm-*-nodejs` packages that utilize NAPI-RS bindings for better performance and compatibility. While `lindera-wasm-unidic-bundler` might function in a Node.js environment *if* it's part of a bundled application, directly using it in Node.js outside a bundler is deprecated in favor of the NAPI-RS variants.","severity":"breaking","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure that `await init();` has completed successfully before creating a `TokenizerBuilder` instance.","cause":"The WebAssembly module was not properly initialized before attempting to instantiate `TokenizerBuilder`.","error":"TypeError: TokenizerBuilder is not a constructor"},{"fix":"Verify that `builder.setDictionary(\"embedded://unidic\");` is correctly specified, as this package contains the UniDic dictionary. Also, check that `await init()` completed successfully.","cause":"The `setDictionary` method was called with an incorrect identifier, or the dictionary asset could not be loaded (e.g., due to an incorrect path or WASM loading issue).","error":"Error: failed to retrieve dictionary"},{"fix":"For Node.js environments, use the `lindera-wasm-unidic-nodejs` package, which is specifically built with NAPI-RS for Node.js compatibility and does not rely on browser-specific APIs.","cause":"The `*-bundler` packages are optimized for browser-like environments. If used directly in a pure Node.js environment without a bundler, they might expect browser global APIs that are not present.","error":"ReferenceError: TextDecoder is not defined (or similar Web API errors in Node.js)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null}