Registry / devops / yargs-interactive

yargs-interactive

JSON →
library3.0.1jsnpmunverified

yargs-interactive is a JavaScript library designed to integrate interactive command-line prompts, powered by Inquirer.js, directly into yargs-based CLIs. This enables developers to create flexible command-line tools that can either parse arguments non-interactively (suitable for scripting and automation) or dynamically prompt users for missing information (for human interaction). The current stable version is 3.0.1, released in April 2022. The project's release cadence appears to be irregular, suggesting a maintenance-focused development cycle rather than active feature additions. Its key differentiation lies in its seamless blending of Yargs' robust argument parsing with Inquirer.js's user-friendly prompting, allowing the same CLI tool to serve diverse use cases, from automated CI/CD pipelines to interactive user experiences, without extensive conditional logic.

npm install yargs-interactive
INSTALL
IMPORT
SIG · YARGS-INTERACTIVE
Y
yargs-interactive
devopsjavascriptv3.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

yargsInteractive
const yargsInteractive = require("yargs-interactive");
import yargsInteractive from 'yargs-interactive';
This library is primarily CommonJS. While Node.js can sometimes interop, direct ESM 'import' might not work as expected without a bundler or specific configuration, leading to `TypeError: yargsInteractive is not a function` or `ReferenceError: require is not defined` if used in an ESM file.
.interactive(options)
yargsInteractive().interactive(options)
yargsInteractive.interactive(options)
The `interactive` method is called on the builder returned by `yargsInteractive()`, not directly on the imported module object.

Demonstrates the basic setup of an interactive CLI, prompting for user input if arguments are not provided via command line.

#!/usr/bin/env node const yargsInteractive = require("yargs-interactive"); const options = { name: { type: "input", default: "A robot", describe: "Enter your name" }, likesPizza: { type: "confirm", default: false, describe: "Do you like pizza?" } }; yargsInteractive() .usage("$0 <command> [args]") .interactive(options) .then(result => { // Your business logic goes here. // Get the arguments from the result console.log(`\nResult is:\n` + `- Name: ${result.name}\n` + `- Likes pizza: ${result.likesPizza}\n`); });
Debug
Known issues
breakingVersion 3.0.0 introduced breaking changes by updating its underlying `yargs` dependency to v14. Users upgrading from v2.x should consult the `yargs` v14 release notes for potential incompatibilities.
fix
Review the `yargs` v14 migration guide and adjust CLI option definitions and usage patterns accordingly. Thorough testing is recommended.
affects: >=3.0.0
breakingVersion 2.0.0 introduced breaking changes to the `prompt` option's contract. Implementations using custom `prompt` behavior will need to be updated.
fix
Refer to the v2.0.0 release notes and documentation for the updated contract of the `prompt` option.
affects: >=2.0.0
gotchaVersions prior to 2.2.0 contained security vulnerabilities. It is crucial to upgrade to v2.2.0 or newer to ensure your CLI is protected against known issues.
fix
Upgrade to `yargs-interactive@^2.2.0` or `yargs-interactive@^3.0.0` immediately.
affects: <2.2.0
gotchaThe minimum Node.js version required is 8. While it may still function on Node.js 8, this version is long End-of-Life and lacks critical security updates and modern JavaScript features. It's recommended to run on a supported Node.js version.
fix
Ensure your environment uses a currently supported Node.js LTS version (e.g., Node.js 16 or newer) for security and performance.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: yargsInteractive is not a function
Attempting to call `yargsInteractive()` when it's not correctly imported/required, often due to ESM `import` in a CJS context or destructuring.
fix
Ensure you are using `const yargsInteractive = require("yargs-interactive");` for CommonJS environments.
Error: Unknown option: --interactive
The `--interactive` flag is not being properly recognized by the `yargs` instance because `.interactive(options)` has not been called on the builder before parsing arguments, or the flag itself is misspelled.
fix
Verify that `yargsInteractive().interactive(options)` is called before any `argv` or `parse` methods, and that the `--interactive` flag is correctly spelled.
ReferenceError: require is not defined in ES module scope
Using `require()` in a JavaScript file that is treated as an ES module (e.g., `.mjs` file or `"type": "module"` in `package.json`).
fix
This library is primarily CJS. Consider sticking to CJS for your CLI entry point, or use a bundler to consume it in an ESM project.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies
yargsrequiredCore dependency for parsing command-line arguments and defining CLI structure.
inquirerrequiredCore dependency for handling interactive prompts and user input.
Agent activity
32 hits · last 30 days
node
26
OpenAI (training)
1
Resources
yargs-interactive — npm install yargs-interactive · libregistry