{"record":{"id":"7725cb624ea79057","repo":"yarnpkg/yarn","slug":"don-t-know-how-to-handle-this-file-type","errorCode":null,"errorMessage":"Don't know how to handle this file type","messagePattern":"Don't know how to handle this file type","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/cli/commands/publish.js","lineNumber":59,"sourceCode":"  if (access && access !== 'public' && access !== 'restricted') {\n    throw new MessageError(config.reporter.lang('invalidAccess'));\n  }\n\n  // TODO this might modify package.json, do we need to reload it?\n  await config.executeLifecycleScript('prepublish');\n  await config.executeLifecycleScript('prepare');\n  await config.executeLifecycleScript('prepublishOnly');\n  await config.executeLifecycleScript('prepack');\n\n  // get tarball stream\n  const stat = await fs.lstat(dir);\n  let stream;\n  if (stat.isDirectory()) {\n    stream = await pack(config);\n  } else if (stat.isFile()) {\n    stream = fs2.createReadStream(dir);\n  } else {\n    throw new Error(\"Don't know how to handle this file type\");\n  }\n  const buffer = await new Promise((resolve, reject) => {\n    const data = [];\n    invariant(stream, 'expected stream');\n    stream.on('data', data.push.bind(data)).on('end', () => resolve(Buffer.concat(data))).on('error', reject);\n  });\n\n  await config.executeLifecycleScript('postpack');\n\n  // copy normalized package and remove internal keys as they may be sensitive or yarn specific\n  pkg = Object.assign({}, pkg);\n  for (const key in pkg) {\n    if (key[0] === '_') {\n      delete pkg[key];\n    }\n  }\n\n  const tag = flags.tag || 'latest';","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/yarnpkg/yarn/blob/c2dda503f3759b5be5f0e24ecd9cf5c97a540147/src/cli/commands/publish.js#L41-L77","documentation":"publish.js:55-61 stats the target path and branches on directory vs. regular file. If `lstat` returns anything that is neither a directory nor a regular file (a symlink whose target is gone, a socket, pipe, device, etc.), it throws the literal Error `Don't know how to handle this file type`.","triggerScenarios":"Passing a broken symlink, a FIFO/socket, or a dangling special file as the publish target: `yarn publish ./some-symlink` whose target no longer exists, or a path that resolves to a non-file inode.","commonSituations":"Broken symlink left by a failed previous step; pointing at a path inside a virtual/overlay filesystem that surfaces as a special node; race where the file was removed between resolve and lstat.","solutions":["Point `yarn publish` at a real directory containing package.json, or at an existing `.tgz` tarball file.","If you passed a symlink, resolve it to its real target or recreate the missing target.","Run `ls -la <path>` and `readlink -f <path>` to confirm the inode type before publishing.","Re-pack with `yarn pack` to produce a fresh `.tgz` and publish that."],"exampleFix":"# before\n$ yarn publish ./mylib.tgz.link   # dangling symlink\n# after\n$ yarn pack && yarn pack ./mylib.tgz   # or publish the real tarball\n$ yarn publish ./mylib-v1.0.0.tgz","handlingStrategy":"validation","validationCode":"const fs = require('fs').promises;\nasync function assertPublishable(path) {\n  const st = await fs.lstat(path);\n  if (!st.isDirectory() && !st.isFile()) {\n    throw new Error(`Unsupported inode type for publish: ${path}`);\n  }\n}","typeGuard":"async function isDirOrFile(path) {\n  const st = await require('fs').promises.lstat(path);\n  return st.isDirectory() || st.isFile();\n}","tryCatchPattern":"try {\n  await runYarn(['publish', target]);\n} catch (e) {\n  if (/Don't know how to handle this file type/.test(e.message)) {\n    console.error('Publish target must be a directory or a .tgz file.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Always pass a directory or a packed `.tgz` to publish.","Resolve symlinks to their real targets before publishing.","Run `yarn pack` first and publish the resulting tarball."],"tags":["cli","publish","filesystem","symlink"],"backgroundTag":null,"analyzedSha":"c2dda503f3759b5be5f0e24ecd9cf5c97a540147","analyzedAt":"2026-08-13T04:17:06.305Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}