{"id":16962,"library":"cli-high","title":"CLI-High: Terminal Syntax Highlighter","description":"cli-high is a lightweight, MIT-licensed JavaScript library providing syntax highlighting specifically designed for terminal output. It is currently at version 0.4.3 and appears to be in active development, having been introduced around 2024. As a \"tiny\" utility, it prioritizes minimal dependencies and a focused scope, primarily offering a single `highlight` function for programmatic use. The library ships with TypeScript types, enabling a robust development experience in TypeScript projects. While its release cadence isn't explicitly defined, as a 0.x.x version, users should anticipate potential API changes in minor or even patch releases. Its primary differentiators are its small footprint and dedicated purpose for aesthetic CLI output, rather than complex, browser-based highlighting solutions.","status":"active","version":"0.4.3","language":"javascript","source_language":"en","source_url":"https://github.com/xinyao27/cli-high","tags":["javascript","cli","highlighter","highlight","color","terminal","console","typescript"],"install":[{"cmd":"npm install cli-high","lang":"bash","label":"npm"},{"cmd":"yarn add cli-high","lang":"bash","label":"yarn"},{"cmd":"pnpm add cli-high","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is the primary named export for programmatic highlighting. While CommonJS might be supported, the library's examples and TypeScript types promote an ESM-first approach. Directly requiring the package might not yield the function.","wrong":"const highlight = require('cli-high')","symbol":"highlight","correct":"import { highlight } from 'cli-high'"},{"note":"Use `import type` for importing the configuration options interface, which allows specifying language, theme, and other highlighting parameters. This ensures type-only imports for better tree-shaking and explicit type usage.","symbol":"Options","correct":"import type { Options } from 'cli-high'"},{"note":"The `Language` type is a string literal union defining the supported language identifiers for the highlighter, useful for type-safe language specification with the `highlight` function's options.","symbol":"Language","correct":"import type { Language } from 'cli-high'"}],"quickstart":{"code":"import { highlight, type Options } from 'cli-high';\n\nconst javascriptCode = `\nfunction greet(name: string) {\n  console.log(\"Hello, \" + name + \"!\");\n}\n\ngreet(\"World\");\n`;\n\nconst options: Options = {\n  language: 'js', // Or 'typescript', 'json', etc.\n  theme: 'dark' // Or 'light'\n};\n\nconst highlightedCode = highlight(javascriptCode, options);\nconsole.log(highlightedCode);\n\n// Example of highlighting a different language\nconst jsonConfig = `{\n  \"name\": \"cli-high-project\",\n  \"version\": \"1.0.0\",\n  \"scripts\": {\n    \"start\": \"node index.js\"\n  }\n}`;\n\nconst highlightedJson = highlight(jsonConfig, { language: 'json' });\nconsole.log('\\n' + highlightedJson);\n","lang":"typescript","description":"Demonstrates programmatic use of `cli-high` to syntax-highlight JavaScript and JSON code for terminal output, including specifying language and theme options."},"warnings":[{"fix":"Always refer to the official GitHub repository and any provided changelog or release notes before upgrading to ensure compatibility with your codebase. Pinning exact versions is recommended for production.","message":"As a 0.x.x version, cli-high's API is subject to breaking changes in minor or even patch releases without strict adherence to SemVer. The API surface may evolve rapidly.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Ensure your project is configured for ES Modules (e.g., `'type': 'module'` in `package.json` or `.mjs` file extension). If you must use CommonJS, consider dynamic `import()` or verify the package's CJS export compatibility.","message":"Mixing CommonJS `require()` with cli-high's presumed ESM-first approach (indicated by TypeScript usage and import examples) can lead to import errors like 'TypeError: highlight is not a function'.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Verify that you are using a named import: `import { highlight } from 'cli-high'`. Check your bundler's configuration for ESM compatibility and ensure no conflicting default imports or incorrect aliasing.","cause":"This error typically occurs in bundled environments (like Webpack) when a named export is incorrectly treated as a default export, or when the `highlight` function is not correctly tree-shaken/imported.","error":"TypeError: (0, cli_high__WEBPACK_IMPORTED_MODULE_0__.highlight) is not a function"},{"fix":"To use ESM, add `'type': 'module'` to your `package.json` file, or save your script files with a `.mjs` extension. Alternatively, if you need to load ESM in a CJS context, use dynamic import: `const { highlight } = await import('cli-high');`.","cause":"Attempting to use ES module `import` syntax in a Node.js environment configured for CommonJS (`require()`) without proper module configuration.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Double-check the file path provided to the `npx cli-high` command. Ensure the file exists and the path is either absolute or correct relative to your current working directory.","cause":"When using `cli-high` via its CLI (`npx cli-high ./path/to/file`), this error indicates that the provided file path does not exist or is incorrect relative to where the command is executed.","error":"Error: ENOENT: no such file or directory, open './path/to/your/js/file'"}],"ecosystem":"npm","meta_description":null}