nodejs/node · error · Error
search must be called with arguments
Error message
search must be called with arguments
What it means
Thrown by `npm search` when, after lowercasing and filtering falsy values, the include list (`args`) is empty. The command requires at least one non-empty search term; `npm search` with no arguments (or only whitespace/empty strings) is meaningless and rejected before any registry call.
Source
Thrown at deps/npm/lib/commands/search.js:35
'searchexclude',
'registry',
'prefer-online',
'prefer-offline',
'offline',
]
static usage = ['<search term> [<search term> ...]']
async exec (args) {
const opts = {
...this.npm.flatOptions,
...this.npm.flatOptions.search,
include: args.map(s => s.toLowerCase()).filter(Boolean),
exclude: this.npm.flatOptions.search.exclude.split(/\s+/),
}
if (opts.include.length === 0) {
throw new Error('search must be called with arguments')
}
// Used later to figure out whether we had any packages go out
let anyOutput = false
// Grab a configured output stream that will spit out packages in the desired format.
const outputStream = formatSearchStream({
args, // --searchinclude options are not highlighted
...opts,
npm: this.npm,
})
log.silly('search', 'searching packages')
const p = new Pipeline(
libSearch.stream(opts.include, opts),
outputStream
)
View on GitHub (pinned to 1b2de5e052)
Solutions
- Provide one or more non-empty search terms: `npm search lodash`.
- In scripts, guard the variable before calling: `npm search "$QUERY"` only when `QUERY` is set.
- Validate the args array length in your wrapper before invoking the CLI.
Example fix
// before npm search // no term // after npm search express
Defensive patterns
Strategy: validation
Validate before calling
function assertSearchArgs(args) {
const include = (args || []).map(s => String(s).toLowerCase()).filter(Boolean)
if (include.length === 0) {
throw new Error('npm search requires at least one non-empty search term')
}
return include
} Prevention
- In shell scripts, guard: `[ -n "$QUERY" ] && npm search "$QUERY"`.
- Validate that search arrays are non-empty before invoking the CLI programmatically.
- Watch for unset environment variables expanding to empty args.
When it happens
Trigger: Calling `npm search` with zero positional args, or with args that all filter to falsy after `s.toLowerCase()` and `Boolean` (e.g. empty strings).
Common situations: Scripted invocation that passes an empty variable (`npm search "$QUERY"` with `QUERY` unset); typo'd flag that consumed the term; shell quoting that stripped the argument.
Related errors
- `npm rebuild` only supports SemVer version/range specifiers
- Missing script: "${event}"${suggestions} To see a list of s
- ${argv[2]} not recognized
- ${argv[2]} not recognized
- First argument `orgname` is required.
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/1fa8e0c993a9682f.
Report an issue: GitHub.