{"id":17531,"library":"cli-alerts","title":"CLI Alerts","description":"cli-alerts is a lightweight, cross-platform utility for Node.js command-line interfaces, designed to display formatted alerts with colored text and symbolic icons. It supports various alert types including success, info, warning, and error, ensuring consistent visual feedback across macOS, Linux, and Windows terminals. The current stable version is 2.0.0. While not following a strict time-based release cadence, the project maintains an active development status with periodic improvements and bug fixes. Its key differentiators include its simplicity, minimal dependencies, and direct focus on enhancing the user experience of CLI tools by providing clear, visually distinct messages without complex configurations, making it an excellent choice for developers looking to add immediate, actionable feedback to their scripts and applications.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/ahmadawais/cli-alerts","tags":["javascript","cli-alerts","Ahmad Awais","ahmadawais","typescript"],"install":[{"cmd":"npm install cli-alerts","lang":"bash","label":"npm"},{"cmd":"yarn add cli-alerts","lang":"bash","label":"yarn"},{"cmd":"pnpm add cli-alerts","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary alert function is typically imported as a default export in ESM contexts, mirroring its CommonJS `require` usage.","wrong":"import { alert } from 'cli-alerts'","symbol":"alert","correct":"import alert from 'cli-alerts'"},{"note":"This is the documented CommonJS usage, compatible with older Node.js projects.","symbol":"alert (CommonJS)","correct":"const alert = require('cli-alerts');"},{"note":"Since the package ships with TypeScript types, you can import the `AlertOptions` interface for strict type checking of the configuration object.","symbol":"AlertOptions (type)","correct":"import type { AlertOptions } from 'cli-alerts';"}],"quickstart":{"code":"import alert from 'cli-alerts';\n\ntype AlertOptions = {\n  type: 'success' | 'info' | 'warning' | 'error';\n  msg: string;\n  name?: string;\n};\n\nconst showAlert = (options: AlertOptions) => {\n  alert(options);\n};\n\n// Example usage:\nconsole.log('\\n--- CLI Alerts Examples ---');\nshowAlert({ type: 'success', msg: 'Operation completed successfully!' });\nshowAlert({ type: 'info', msg: 'Checking for updates...' });\nshowAlert({ type: 'warning', msg: 'Configuration file missing, using defaults.', name: 'CONFIG' });\nshowAlert({ type: 'error', msg: 'Failed to connect to the server. Please try again.' });\nconsole.log('--- End Examples ---\\n');\n\n// To run this: \n// 1. npm install cli-alerts\n// 2. Save as 'app.ts'\n// 3. npx ts-node app.ts","lang":"typescript","description":"Demonstrates how to import and use the 'alert' function for various message types with TypeScript."},"warnings":[{"fix":"Consult the project's official changelog (changelog.md within the repository) for a detailed list of breaking changes and migration steps before upgrading.","message":"The package moved to v2.0.0, indicating potential breaking changes according to semantic versioning. While specific details were not provided in the readily available documentation, users upgrading from v1.x should review the changelog for any API alterations.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"For ESM projects, use `import alert from 'cli-alerts';`. For CommonJS projects, stick to `const alert = require('cli-alerts');`. If you encounter `ERR_REQUIRE_ESM`, refactor your module imports to be consistent or ensure your environment supports interoperability (e.g., Node.js >=14 with appropriate flags or transpilation).","message":"When using ESM in a Node.js project, ensure your `package.json` specifies `\"type\": \"module\"` or use `.mjs` file extensions. Mixing CommonJS `require()` with ESM `import` in the same file can lead to `ERR_REQUIRE_ESM` errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"If your project is ESM, change `const alert = require('cli-alerts');` to `import alert from 'cli-alerts';`. If your project is CommonJS, ensure `cli-alerts` itself is not an ESM-only package that's incompatible, or use a tool like `ts-node` or `esm` package for better interoperability.","cause":"Attempting to `require()` an ESM-only module in a CommonJS context, or vice-versa, without proper configuration or transpilation.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported"},{"fix":"Verify your import statement matches the module's export style. For `cli-alerts`, in ESM, use `import alert from 'cli-alerts';` (default import). In CommonJS, use `const alert = require('cli-alerts');`.","cause":"Incorrect import statement (e.g., named import `{ alert }` instead of default import `alert`), or attempting to call `alert` on a non-function.","error":"TypeError: alert is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}