yarnpkg/yarn · error · MessageError
invalidPackageName
Error message
invalidPackageName
What it means
Before mutating package owners, the owner command resolves the package name and validates it with `isValidPackageName(name)` (owner.js:31). If the name fails npm naming rules, it throws invalidPackageName before contacting the registry.
Source
Thrown at src/cli/commands/owner.js:32
success: string,
error: string,
};
export async function mutate(
args: Array<string>,
config: Config,
reporter: Reporter,
buildMessages: (username: string, packageName: string) => Messages,
mutator: (user: Object, pkg: Object) => boolean,
): Promise<boolean> {
if (args.length !== 2 && args.length !== 1) {
return false;
}
const username = args.shift();
const name = await getName(args, config);
if (!isValidPackageName(name)) {
throw new MessageError(reporter.lang('invalidPackageName'));
}
const msgs = buildMessages(username, name);
reporter.step(1, 3, reporter.lang('loggingIn'));
const revoke = await getToken(config, reporter, name);
reporter.step(2, 3, msgs.info);
const user = await config.registries.npm.request(`-/user/org.couchdb.user:${username}`);
let error = false;
if (user) {
// get package
const pkg = await config.registries.npm.request(NpmRegistry.escapeName(name));
if (pkg) {
pkg.maintainers = pkg.maintainers || [];
error = mutator({name: user.name, email: user.email}, pkg);
} else {
error = true;
reporter.error(reporter.lang('unknownPackage', name));View on GitHub (pinned to c2dda503f3)
Solutions
- Use the exact published package name (check it on the registry or in package.json `name`).
- For scoped packages pass `@scope/name` with lowercase alphanumeric, hyphens, and underscores only.
- Avoid uppercase, spaces, and leading punctuation in the name argument.
Example fix
// before $ yarn owner add alice My-Lib // after $ yarn owner add alice my-lib
Defensive patterns
Strategy: validation
Validate before calling
// Mirror npm's package-name rules before calling owner commands
function isValidPackageName(name) {
return /^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(name);
}
if (!isValidPackageName(pkgName)) {
throw new Error(`'${pkgName}' is not a valid npm package name.`);
} Type guard
function isValidPackageName(name) {
return typeof name === 'string' &&
/^(?:@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(name);
} Try / catch
try {
await runYarn(['owner', verb, user, pkgName]);
} catch (e) {
if (/invalidPackageName/.test(e.message)) {
console.error(`'${pkgName}' must be lowercase, no spaces, valid scope.`);
return;
}
throw e;
} Prevention
- Always pass the exact published `name` from package.json.
- Validate scoped names with `@scope/name` lowercase form.
- Never substitute a display title for the package identifier.
When it happens
Trigger: Running `yarn owner add/remove <user> <pkg>` where `<pkg>` contains uppercase letters, spaces, leading dots/underscores, invalid special chars, or a malformed scope like `@scope` without a name.
Common situations: Passing a display name instead of the package identifier; copy-pasting a scoped name with a typo; using a local folder name that doesn't match the published name.
Related errors
- Name should not start with "/", got "${str}"
- Name should not start with ".", got "${str}"
- invalidAccess
- tooManyArguments
- unknownFolderOrTarball
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/77476231e3fa2624.
Report an issue: GitHub.