yarnpkg/yarn · error · MessageError
publishPrivate
Error message
publishPrivate
What it means
publish.js:146-147 reads the root manifest and, if `pkg.private` is truthy, throws publishPrivate. The `private` flag exists precisely to prevent accidental publication of internal packages.
Source
Thrown at src/cli/commands/publish.js:147
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'));
}
if (!pkg.name) {
throw new MessageError(reporter.lang('noName'));
}
let registry: string = '';
if (pkg && pkg.publishConfig && pkg.publishConfig.registry) {
registry = pkg.publishConfig.registry;
}
reporter.step(1, 4, reporter.lang('bumpingVersion'));
const commitVersion = await setVersion(config, reporter, flags, [], false);
//
reporter.step(2, 4, reporter.lang('loggingIn'));
const revoke = await getToken(config, reporter, pkg.name, flags, registry);
View on GitHub (pinned to c2dda503f3)
Solutions
- If publication is genuinely intended, remove `"private": true` (or set it false) from package.json.
- If the package should stay private, this error is correct—do not publish; abort the workflow.
- For monorepo setups, publish from the specific workspace package that is NOT marked private, not the private root.
Example fix
// before — package.json
{
"name": "myapp",
"private": true
}
// after (only if you truly intend to publish)
{
"name": "mylib",
"private": false
} Defensive patterns
Strategy: validation
Validate before calling
const pkg = require('./package.json');
if (pkg.private) {
throw new Error('Refusing to publish: package.json has "private: true".');
} Type guard
function isPublishable(pkg) {
return typeof pkg === 'object' && pkg !== null && !pkg.private;
} Try / catch
try {
await runYarn(['publish']);
} catch (e) {
if (/publishPrivate/.test(e.message)) {
console.error('Package is marked private; remove the flag only if publication is intended.');
return;
}
throw e;
} Prevention
- Keep apps/roots `private: true`; never publish them.
- Add a pre-publish check that aborts on `private: true`.
- Publish from non-private workspace packages, not monorepo roots.
When it happens
Trigger: Running `yarn publish` on a package.json that contains `"private": true` (common for apps, monorepo roots, and internal libraries that must never be published).
Common situations: Trying to publish an application/private lib; monorepo root marked private; copy-pasted package.json that retained `private: true` from a template.
Related errors
- invalidAccess
- Don't know how to handle this file type
- publishFail
- tooManyArguments
- unknownFolderOrTarball
AI-assisted analysis of yarnpkg/yarn@c2dda503f3 (2026-08-13).
Data as JSON: /api/errors/9527bfd872c969e5.
Report an issue: GitHub.