nodejs/node · error · Error
First argument `orgname` is required.
Error message
First argument `orgname` is required.
What it means
Thrown by the `org set` method (alias `org add`) when the first positional argument `orgname` is missing or falsy. The `set` method assigns a user a role within an npm organization and requires at minimum an org name, a username, and optionally a role (defaults to 'developer'). Without an org name, the API call cannot proceed.
Source
Thrown at deps/npm/lib/commands/org.js:55
}, opts => {
switch (cmd) {
case 'add':
case 'set':
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(View on GitHub (pinned to 1b2de5e052)
Solutions
- Provide the org name as the first argument: `npm org set <orgname> <username> [role]`
- If scripting, validate that the org name variable is non-empty before invoking the command
- Check `npm org --help` for correct argument order
Example fix
// before npm org set someuser developer // after — orgname must come first npm org set my-org someuser developer
Defensive patterns
Strategy: validation
Validate before calling
function validateOrgArgs(org, user, role) {
if (!org) throw new Error('orgname is required')
if (!user) throw new Error('username is required')
const validRoles = ['owner', 'admin', 'developer']
if (role && !validRoles.includes(role)) throw new Error(`Invalid role: ${role}`)
} Type guard
function hasOrgName(org) {
return typeof org === 'string' && org.trim().length > 0
} Try / catch
try {
await exec(['set', orgName, userName, role])
} catch (e) {
if (e.message.includes('orgname')) {
console.error('Usage: npm org set <orgname> <username> [role]')
}
throw e
} Prevention
- Always pass arguments in the correct order: orgname, username, role
- In scripts, validate that org name is a non-empty string before calling npm org set
- Use npm org set --help to confirm the argument layout
When it happens
Trigger: Running `npm org set` (or `npm org add`) without any arguments, or with an empty/undefined first argument. The exec method destructures `[cmd, orgname, username, role]` from args, and if orgname is undefined/falsy when set/add is dispatched, this throws.
Common situations: Typing `npm org set` and forgetting arguments, or scripting the command without checking that the org name variable is populated. Using a script that reads org name from an environment variable that was not set.
Related errors
- Second argument `username` 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/a54998802489fb66.
Report an issue: GitHub.