yarnpkg/yarn · error · MessageError
tooManyArguments
Error message
tooManyArguments
What it means
`yarn publish` accepts zero or one positional argument (an optional directory or tarball path, publish.js:128-130). If more than one positional arg is passed it throws tooManyArguments with the max count (1).
Source
Thrown at src/cli/commands/publish.js:130
try {
await config.registries.npm.request(NpmRegistry.escapeName(pkg.name), {
registry: pkg && pkg.publishConfig && pkg.publishConfig.registry,
method: 'PUT',
body: root,
});
} catch (error) {
throw new MessageError(config.reporter.lang('publishFail', error.message));
}
await config.executeLifecycleScript('publish');
await config.executeLifecycleScript('postpublish');
}
export async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {
// validate arguments
const dir = args[0] ? path.resolve(config.cwd, args[0]) : config.cwd;
if (args.length > 1) {
throw new MessageError(reporter.lang('tooManyArguments', 1));
}
if (!await fs.exists(dir)) {
throw new MessageError(reporter.lang('unknownFolderOrTarball'));
}
const stat = await fs.lstat(dir);
let publishPath = dir;
if (stat.isDirectory()) {
config.cwd = path.resolve(dir);
publishPath = config.cwd;
}
// validate package fields that are required for publishing
// $FlowFixMe
const pkg = await config.readRootManifest();
if (pkg.private) {
throw new MessageError(reporter.lang('publishPrivate'));
}View on GitHub (pinned to c2dda503f3)
Solutions
- Pass at most one path: `yarn publish` (uses cwd) or `yarn publish ./pkg-dir` or `yarn publish ./pkg.tgz`.
- If you have multiple tarballs, publish them in separate invocations.
- Quote arguments and check `"$@"` length in wrapper scripts before forwarding.
Example fix
# before $ yarn publish ./pkg ./other # after $ yarn publish ./pkg
Defensive patterns
Strategy: validation
Validate before calling
function assertPublishArgs(args) {
if (args.length > 1) {
throw new Error(`yarn publish takes at most 1 positional arg, got ${args.length}.`);
}
} Try / catch
try {
await runYarn(['publish', ...args]);
} catch (e) {
if (/tooManyArguments/.test(e.message)) {
console.error('Pass only one dir/tarball path to yarn publish.');
return;
}
throw e;
} Prevention
- Treat `yarn publish` as 0-or-1 positional args.
- Quote globs and check arg counts in wrapper scripts.
- Publish multiple tarballs in separate invocations.
When it happens
Trigger: Running `yarn publish ./dir extra`, `yarn publish a.tgz b.tgz`, or a wrapper script that appends multiple path arguments.
Common situations: Shell glob expanding to multiple tarballs; script passing both a dir and a version flag positionally; misunderstanding the command signature.
Related errors
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/301799d6e304bdd4.
Report an issue: GitHub.