nodejs/node · error · Error
Second argument `username` is required.
Error message
Second argument `username` is required.
What it means
Thrown by the `org set` method when the org name is present but the second argument `username` is missing or falsy. The set operation requires knowing which user to add/modify in the org, so a missing username is a fatal precondition failure.
Source
Thrown at deps/npm/lib/commands/org.js:59
return this.set(orgname, username, role, opts)
case 'rm':
return this.rm(orgname, username, opts)
case 'ls':
return this.ls(orgname, username, opts)
default:
throw this.usageError()
}
})
}
async set (org, user, role, opts) {
role = role || 'developer'
if (!org) {
throw new Error('First argument `orgname` is required.')
}
if (!user) {
throw new Error('Second argument `username` is required.')
}
if (!['owner', 'admin', 'developer'].find(x => x === role)) {
throw new Error(
'Third argument `role` must be one of `owner`, `admin`, or `developer`, with `developer` being the default value if omitted.'
)
}
const memDeets = await liborg.set(org, user, role, opts)
if (opts.json) {
output.standard(JSON.stringify(memDeets, null, 2))
} else if (opts.parseable) {
output.standard(['org', 'orgsize', 'user', 'role'].join('\t'))
output.standard(
[memDeets.org.name, memDeets.org.size, memDeets.user, memDeets.role].join('\t')
)
} else if (!this.npm.silent) {
output.standard(View on GitHub (pinned to 1b2de5e052)
Solutions
- Supply the username as the second argument: `npm org set <orgname> <username> [role]`
- In scripts, assert the username variable is a non-empty string before calling
- Review the argument order with `npm org set --help`
Example fix
// before npm org set my-org // after npm org set my-org someuser
Defensive patterns
Strategy: validation
Validate before calling
function validateOrgSetArgs(org, user) {
if (!org) throw new Error('orgname is required')
if (!user) throw new Error('username is required')
} Type guard
function hasUsername(user) {
return typeof user === 'string' && user.trim().length > 0
} Try / catch
try {
await exec(['set', orgName, userName, role])
} catch (e) {
if (e.message.includes('username')) {
console.error('Usage: npm org set <orgname> <username> [role]')
}
throw e
} Prevention
- Always include the username as the second positional argument
- In scripts, assert username is non-empty before invoking npm org set
- Remember the argument order: org first, then user, then role
When it happens
Trigger: Running `npm org set my-org` without a username argument. The args are destructured as `[cmd, orgname, username, role]`; if username resolves to undefined after org passes its check, this error fires.
Common situations: Forgetting the username in the command, or passing it in the wrong positional slot. Scripting the command where the username variable resolved to empty due to a variable naming error.
Related errors
- First argument `orgname` is required.
- Third argument `role` must be one of `owner`, `admin`, or `d
- ${argv[2]} not recognized
- Unknown profile command: ${subcmd}
- npm profile set <prop> <value>
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/fac0a13da8398a47.
Report an issue: GitHub.