{"id":15123,"library":"hunspell-spellchecker","title":"Hunspell Spellchecker in Javascript","description":"hunspell-spellchecker is a lightweight JavaScript library designed to parse and utilize Hunspell dictionaries (typically `.aff` and `.dic` files) within a JavaScript environment. It facilitates the conversion of these dictionary files into a JSON format, which can then be efficiently loaded and used for spell-checking. The library supports both Node.js for server-side processing and, with careful pre-processing, browser environments. The current stable version is 1.0.2, last published over 11 years ago, indicating it is no longer actively maintained. Its primary differentiator is the ability to work directly with Hunspell dictionary formats, converting them to a more JavaScript-friendly JSON structure for use in applications requiring custom or offline spell-checking capabilities.","status":"abandoned","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/GitbookIO/hunspell-spellchecker","tags":["javascript","licenses"],"install":[{"cmd":"npm install hunspell-spellchecker","lang":"bash","label":"npm"},{"cmd":"yarn add hunspell-spellchecker","lang":"bash","label":"yarn"},{"cmd":"pnpm add hunspell-spellchecker","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only, last published over 11 years ago. ESM imports are not natively supported and require a CommonJS wrapper or bundler configuration.","wrong":"import Spellchecker from 'hunspell-spellchecker';","symbol":"Spellchecker","correct":"const Spellchecker = require('hunspell-spellchecker');"},{"note":"The library exports a constructor function, not a direct instance or a factory function. It must be instantiated with `new`.","wrong":"const spellchecker = hunspell_spellchecker();","symbol":"Spellchecker (instance)","correct":"const spellchecker = new Spellchecker();"}],"quickstart":{"code":"const fs = require('fs');\nconst path = require('path');\nconst Spellchecker = require('hunspell-spellchecker');\n\n// Initialize a spellchecker instance\nconst spellchecker = new Spellchecker();\n\n// Example dictionary files (replace with actual paths)\n// For demonstration, these files must exist in your project root\n// or be accessible via `fs.readFileSync`.\n// You would typically download official Hunspell dictionaries (e.g., from LibreOffice).\nconst affFilePath = path.join(__dirname, 'en_US.aff'); // Placeholder\nconst dicFilePath = path.join(__dirname, 'en_US.dic'); // Placeholder\n\n// In a real application, ensure these files exist\n// For testing, you might create dummy files or skip this part.\nif (!fs.existsSync(affFilePath) || !fs.existsSync(dicFilePath)) {\n  console.error('Error: Dictionary files (en_US.aff, en_US.dic) not found.');\n  console.error('Please download them or provide valid paths for parsing.');\n  console.error('For example, download from: https://extensions.libreoffice.org/extensions/english-dictionaries (rename .oxt to .zip)');\n  process.exit(1);\n}\n\n// Parse an hunspell dictionary that can be serialized as JSON\nconst DICT = spellchecker.parse({\n    aff: fs.readFileSync(affFilePath),\n    dic: fs.readFileSync(dicFilePath)\n});\n\n// Load a serialized dictionary into the spellchecker\nspellchecker.use(DICT);\n\n// Check a word\nconst wordToCheck = 'typo';\nconst isRight = spellchecker.check(wordToCheck);\n\nconsole.log(`Is '${wordToCheck}' spelled correctly? ${isRight}`); // Should be false\n\nconst correctWord = 'hello';\nconst isCorrect = spellchecker.check(correctWord);\nconsole.log(`Is '${correctWord}' spelled correctly? ${isCorrect}`); // Should be true","lang":"javascript","description":"This quickstart demonstrates how to initialize the spellchecker, parse Hunspell dictionary files (.aff and .dic) from the filesystem, load the processed dictionary, and then check the spelling of a word. It assumes dictionary files are available locally."},"warnings":[{"fix":"Migrate to a contemporary spell-checking library such as `nspell` (JavaScript-based) or integrate with `Nuspell` (C++ with bindings) for more robust, actively maintained solutions.","message":"This package is abandoned and has not been updated in over 11 years. It is unlikely to receive security patches, bug fixes, or new features. Consider more actively maintained alternatives like `nspell` or `nuspell` for modern applications.","severity":"breaking","affected_versions":"<=1.0.2"},{"fix":"For browser usage, pre-parse the `.aff` and `.dic` files into the JSON format using Node.js or a build step, then serve and load the JSON dictionary directly in the browser. Do not attempt to use `fs.readFileSync` client-side.","message":"The example code relies on Node.js's `fs.readFileSync` for parsing dictionary files. This makes the parsing step inherently server-side. Direct use in a browser environment will fail unless dictionary files are pre-parsed into JSON and loaded, or `fs` is polyfilled/mocked.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"In Node.js ESM projects, use `const Spellchecker = require('hunspell-spellchecker');` if allowed, or configure your bundler (e.g., Webpack, Rollup) to correctly handle CommonJS modules. If strict ESM is required, consider alternative libraries.","message":"The library is CommonJS-only and does not natively support ES Modules (ESM) `import` syntax. Attempting to use `import Spellchecker from 'hunspell-spellchecker'` in an ESM context will likely result in errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure your project is configured for CommonJS, or if using ESM, adjust your build setup to handle CommonJS imports. For strict ESM, rewrite the import statement using `import * as Spellchecker from 'hunspell-spellchecker';` (though this package is CJS-first, this might still lead to issues) or use dynamic `import('hunspell-spellchecker')`.","cause":"Attempting to use `require()` in an ES Module (ESM) context without proper configuration or transpilation.","error":"ReferenceError: require is not defined"},{"fix":"The `fs` module is a Node.js built-in. Dictionary parsing must occur on the server-side (Node.js) or as part of a build process. Only the resulting JSON dictionary should be loaded in the browser.","cause":"Trying to run the dictionary parsing example code directly in a browser environment.","error":"TypeError: fs.readFileSync is not a function"},{"fix":"Verify the file paths provided to `fs.readFileSync()` are absolute or correctly relative to `process.cwd()` (Node.js) or `__dirname`. Ensure the dictionary files are present in the expected location.","cause":"The specified Hunspell dictionary (`.aff` or `.dic`) file path is incorrect or the file does not exist at the given location.","error":"Error: ENOENT: no such file or directory, open './en_EN.aff'"}],"ecosystem":"npm"}