{"record":{"id":"9527bfd872c969e5","repo":"yarnpkg/yarn","slug":"publishprivate","errorCode":null,"errorMessage":"publishPrivate","messagePattern":"publishPrivate","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/publish.js","lineNumber":147,"sourceCode":"  if (args.length > 1) {\n    throw new MessageError(reporter.lang('tooManyArguments', 1));\n  }\n  if (!await fs.exists(dir)) {\n    throw new MessageError(reporter.lang('unknownFolderOrTarball'));\n  }\n\n  const stat = await fs.lstat(dir);\n  let publishPath = dir;\n  if (stat.isDirectory()) {\n    config.cwd = path.resolve(dir);\n    publishPath = config.cwd;\n  }\n\n  // validate package fields that are required for publishing\n  // $FlowFixMe\n  const pkg = await config.readRootManifest();\n  if (pkg.private) {\n    throw new MessageError(reporter.lang('publishPrivate'));\n  }\n  if (!pkg.name) {\n    throw new MessageError(reporter.lang('noName'));\n  }\n\n  let registry: string = '';\n\n  if (pkg && pkg.publishConfig && pkg.publishConfig.registry) {\n    registry = pkg.publishConfig.registry;\n  }\n\n  reporter.step(1, 4, reporter.lang('bumpingVersion'));\n  const commitVersion = await setVersion(config, reporter, flags, [], false);\n\n  //\n  reporter.step(2, 4, reporter.lang('loggingIn'));\n  const revoke = await getToken(config, reporter, pkg.name, flags, registry);\n","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/publish.js#L129-L165","documentation":"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.","triggerScenarios":"Running `yarn publish` on a package.json that contains `\"private\": true` (common for apps, monorepo roots, and internal libraries that must never be published).","commonSituations":"Trying to publish an application/private lib; monorepo root marked private; copy-pasted package.json that retained `private: true` from a template.","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."],"exampleFix":"// before — package.json\n{\n  \"name\": \"myapp\",\n  \"private\": true\n}\n// after (only if you truly intend to publish)\n{\n  \"name\": \"mylib\",\n  \"private\": false\n}","handlingStrategy":"validation","validationCode":"const pkg = require('./package.json');\nif (pkg.private) {\n  throw new Error('Refusing to publish: package.json has \"private: true\".');\n}","typeGuard":"function isPublishable(pkg) {\n  return typeof pkg === 'object' && pkg !== null && !pkg.private;\n}","tryCatchPattern":"try {\n  await runYarn(['publish']);\n} catch (e) {\n  if (/publishPrivate/.test(e.message)) {\n    console.error('Package is marked private; remove the flag only if publication is intended.');\n    return;\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["cli","publish","private","safety-guard"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}