{"record":{"id":"f3d34faeda1340bc","repo":"yarnpkg/yarn","slug":"unknownfolderortarball","errorCode":null,"errorMessage":"unknownFolderOrTarball","messagePattern":"unknownFolderOrTarball","errorType":"exception","errorClass":"MessageError","httpStatus":null,"severity":"error","filePath":"src/cli/commands/publish.js","lineNumber":133,"sourceCode":"      method: 'PUT',\n      body: root,\n    });\n  } catch (error) {\n    throw new MessageError(config.reporter.lang('publishFail', error.message));\n  }\n\n  await config.executeLifecycleScript('publish');\n  await config.executeLifecycleScript('postpublish');\n}\n\nexport async function run(config: Config, reporter: Reporter, flags: Object, args: Array<string>): Promise<void> {\n  // validate arguments\n  const dir = args[0] ? path.resolve(config.cwd, args[0]) : config.cwd;\n  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  }","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/publish.js#L115-L151","documentation":"After resolving the publish path (`args[0]` or cwd, publish.js:131), yarn checks existence with `fs.exists(dir)`; a non-existent path throws unknownFolderOrTarball before it ever stats the target.","triggerScenarios":"Running `yarn publish ./does-not-exist`, a typo'd relative path, or a path from an env var that wasn't set (resolving to an empty/garbage string).","commonSituations":"Typo in the directory name; CI passing an unset `${PKG_DIR}` variable; path computed before the artifact was created (e.g., pack hadn't run yet).","solutions":["Verify the path exists: `ls -la <path>` before publishing.","Ensure any `pack`/build step that produces the dir or tarball has completed first.","In scripts, default to cwd (`yarn publish`) or guard with `[ -e \"$PKG_DIR\" ]`."],"exampleFix":"# before\n$ yarn publish ./bulid        # typo, unknownFolderOrTarball\n# after\n$ yarn publish ./build","handlingStrategy":"validation","validationCode":"const fs = require('fs').promises;\nasync function assertTargetExists(p) {\n  try { await fs.access(p); }\n  catch { throw new Error(`Publish target does not exist: ${p}`); }\n}","typeGuard":"async function pathExists(p) {\n  try { await require('fs').promises.access(p); return true; }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  await runYarn(['publish', target]);\n} catch (e) {\n  if (/unknownFolderOrTarball/.test(e.message)) {\n    console.error(`Path not found: ${target}`);\n    return;\n  }\n  throw e;\n}","preventionTips":["Verify the publish path exists before invoking yarn.","Default unset env vars to cwd or fail explicitly.","Ensure pack/build completes before publish in CI ordering."],"tags":["cli","publish","filesystem","validation"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}