{"id":17023,"library":"inquirer-autocomplete-standalone","title":"CLI Autocomplete Prompt (Standalone)","description":"Inquirer-autocomplete-standalone provides a robust and flexible command-line interface prompt for displaying dynamic, filterable choices to users. It functions as a standalone component built on the core principles of Inquirer.js, allowing developers to integrate autocomplete functionality without needing the full `inquirer-autocomplete-prompt` package. This package, currently at version 0.8.1, is designed as a native ECMAScript module (ESM), requiring Node.js environments that support ESM. It supports both synchronous and asynchronous data sources, making it ideal for scenarios where choices need to be fetched from external APIs or computed on-the-fly based on user input. Its key differentiator is its modular, standalone nature, aligning with the modern Inquirer.js approach of independent prompts. This contrasts with the legacy `inquirer-autocomplete-prompt` package, which transitioned to ESM in v3 and provided a CJS fallback in v2. Users seeking a modern, ESM-first autocomplete prompt should opt for this package. While no explicit release cadence is stated for this specific `standalone` package, its parent project and related `inquirer-autocomplete-prompt` indicate active maintenance.","status":"active","version":"0.8.1","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/mokkabonna/inquirer-autocomplete-prompt","tags":["javascript","answer","answers","ask","base","cli","command","command-line","enquirer","typescript"],"install":[{"cmd":"npm install inquirer-autocomplete-standalone","lang":"bash","label":"npm"},{"cmd":"yarn add inquirer-autocomplete-standalone","lang":"bash","label":"yarn"},{"cmd":"pnpm add inquirer-autocomplete-standalone","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is an ES module. For CommonJS, use dynamic import: `const { default: autocomplete } = await import('inquirer-autocomplete-standalone');`","wrong":"const autocomplete = require('inquirer-autocomplete-standalone');","symbol":"autocomplete","correct":"import autocomplete from 'inquirer-autocomplete-standalone';"},{"note":"Named exports are also ESM-only. For CommonJS, use dynamic import: `const { Separator } = await import('inquirer-autocomplete-standalone');`","wrong":"const { Separator } = require('inquirer-autocomplete-standalone');","symbol":"Separator","correct":"import { Separator } from 'inquirer-autocomplete-standalone';"},{"note":"Types like `Choice` and `Separator` are available for TypeScript users directly from the package. Ensure your `tsconfig.json` supports ESM imports if emitting CommonJS.","symbol":"Type (generic)","correct":"import autocomplete, { Separator, Choice } from 'inquirer-autocomplete-standalone';"}],"quickstart":{"code":"import autocomplete from 'inquirer-autocomplete-standalone';\n\ninterface CountryChoice {\n  value: string;\n  description: string;\n}\n\n// Mock an asynchronous search function that simulates an API call\nasync function searchCountries(input?: string): Promise<string[]> {\n  const allCountries = [\n    'Norway', 'Sweden', 'Denmark', 'Finland', 'Iceland',\n    'Germany', 'France', 'Spain', 'Italy', 'Portugal',\n    'United Kingdom', 'Ireland', 'Canada', 'United States',\n    'Mexico', 'Brazil', 'Argentina', 'Australia', 'New Zealand',\n    'Japan', 'China', 'India', 'South Africa'\n  ];\n  const normalizedInput = (input || '').toLowerCase();\n  await new Promise(resolve => setTimeout(resolve, 100)); // Simulate API delay\n  return allCountries.filter(country =>\n    country.toLowerCase().includes(normalizedInput)\n  ).slice(0, 10); // Limit results to 10 for display\n}\n\nasync function runPrompt() {\n  console.log('Starting autocomplete prompt...');\n  const answer = await autocomplete<string>({ // Specify the type for the selected value\n    message: 'Travel from what country?',\n    source: async (input) => {\n      const filteredCountries = await searchCountries(input);\n      return filteredCountries.map(country => ({\n        value: country,\n        description: `${country} is a great place to visit`,\n      }));\n    },\n    // Optional settings:\n    // default: 'Norway', // Pre-select a default value\n    // suggestOnly: false, // If true, allows arbitrary input not in the list\n  });\n\n  console.log(`\\nYou selected: ${answer}`);\n  process.exit(0); // Ensure the process exits cleanly after prompt interaction\n}\n\nrunPrompt().catch(console.error);\n","lang":"typescript","description":"Demonstrates a basic asynchronous autocomplete prompt, allowing users to select a country from a dynamically filtered list, simulating an external API call."},"warnings":[{"fix":"Ensure your project is configured for ESM (add `\"type\": \"module\"` to `package.json` and use `import` statements), or use dynamic `await import()` for CommonJS environments: `const { default: autocomplete } = await import('inquirer-autocomplete-standalone');`","message":"The `inquirer-autocomplete-standalone` package is fundamentally an ECMAScript Module (ESM). It does not support direct `require()` calls in CommonJS environments. Attempting to use `require()` will result in import errors.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Always verify you are installing `inquirer-autocomplete-standalone` for the modern, standalone prompt experience. If you need the legacy `inquirer-autocomplete-prompt` for Inquirer v9 or older, install that specifically.","message":"There are two similarly named packages: `inquirer-autocomplete-standalone` (this package, recommended, ESM-first, standalone) and `inquirer-autocomplete-prompt` (the legacy package, which has CJS v2 and ESM v3). Installing the wrong package is a common mistake that leads to import errors or unexpected behavior.","severity":"gotcha","affected_versions":"All"},{"fix":"Consult the official TypeScript documentation or examples (e.g., the `import-esm-in-typescript-examples` repository linked in the package README) for guidance on configuring `tsconfig.json` with settings like `\"esModuleInterop\": true` and `\"moduleResolution\": \"bundler\"` or `\"node16\"`.","message":"When using `inquirer-autocomplete-standalone` (an ESM package) within a TypeScript project that is configured to emit CommonJS, you may encounter module resolution issues. Specific `tsconfig.json` settings are often required for correct compilation and runtime behavior.","severity":"gotcha","affected_versions":"All"},{"fix":"Refer to the usage examples for `inquirer-autocomplete-standalone` and the latest Inquirer.js documentation on integrating custom or standalone prompts.","message":"While designed to integrate seamlessly with Inquirer.js, `inquirer-autocomplete-standalone` functions as a decoupled prompt. Users migrating from the legacy `inquirer-autocomplete-prompt` might need to adapt their Inquirer.js registration or usage patterns (e.g., `inquirer.registerPrompt`) to utilize this standalone version effectively.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Add `\"type\": \"module\"` to your `package.json` to make your project an ESM module, or use dynamic import for this package in CommonJS: `const { default: autocomplete } = await import('inquirer-autocomplete-standalone');`","cause":"Attempting to use an `import` statement for `inquirer-autocomplete-standalone` in a CommonJS project without proper ESM configuration.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"For CommonJS, ensure you are using dynamic import and correctly accessing the default export: `const { default: autocomplete } = await import('inquirer-autocomplete-standalone');`. Verify the package is correctly installed.","cause":"Occurs when attempting to use `require('inquirer-autocomplete-standalone')` and treating the result as a function, which is incorrect for an ESM default export when dynamically imported in CJS, or when `require` fails to resolve the module.","error":"TypeError: autocomplete is not a function"},{"fix":"Run `npm install inquirer-autocomplete-standalone`. If `inquirer-autocomplete-prompt` was mistakenly installed, uninstall it first with `npm uninstall inquirer-autocomplete-prompt`.","cause":"The package `inquirer-autocomplete-standalone` is not installed or the `inquirer-autocomplete-prompt` (legacy) package was installed instead.","error":"Error: Cannot find module 'inquirer-autocomplete-standalone'"}],"ecosystem":"npm","meta_description":null}