{"record":{"id":"277303c6ea0ded8b","repo":"gatsbyjs/gatsby","slug":"failed-to-write-file-into-outputpath-err","errorCode":null,"errorMessage":"Failed to write ${file} into ${outputPath}. (${err.message})","messagePattern":"Failed to write (.+?) into (.+?)\\. \\((.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gatsby-plugin-sharp/src/process-file.ts","lineNumber":136,"sourceCode":"        // rotate\n        if (transformArgs.rotate && transformArgs.rotate !== 0) {\n          clonedPipeline = clonedPipeline.rotate(transformArgs.rotate)\n        }\n\n        // duotone\n        if (transformArgs.duotone) {\n          clonedPipeline = await duotone(\n            transformArgs.duotone,\n            transformArgs.toFormat,\n            clonedPipeline\n          )\n        }\n\n        try {\n          const buffer = await clonedPipeline.toBuffer()\n          await fs.writeFile(outputPath, buffer)\n        } catch (err) {\n          throw new Error(\n            `Failed to write ${file} into ${outputPath}. (${err.message})`\n          )\n        }\n      } catch (err) {\n        if (err instanceof SharpError) {\n          // rethrow\n          throw err\n        }\n\n        throw new SharpError(`Processing ${file} failed`, err)\n      }\n\n      return transform\n    })\n  )\n}\n\nexport const createArgsDigest = (args: unknown): string => {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-plugin-sharp/src/process-file.ts#L118-L154","documentation":"During each transform, process-file.ts runs the cloned sharp pipeline to a buffer and writes it to outputPath. If toBuffer fails (sharp could not encode, e.g. unsupported output format or processing error mid-pipeline) or fs.writeFile fails (disk full, permission denied, missing parent dir despite ensureDir), the error is re-thrown with the input file, the output path, and the underlying message.","triggerScenarios":"Output directory becomes unwritable mid-build; disk full; outputPath is on a read-only mount; sharp fails to encode the requested format (e.g. avif without libheif); the transform produces an empty/invalid buffer; duotone/toFormat combination sharp cannot satisfy.","commonSituations":"CI runners out of disk; Docker bind mounts with wrong permissions; switching toFormat to avif/webp without a sharp build that supports it; concurrent builds writing to the same public dir.","solutions":["Check free disk space and write permissions on the output/cache directory (df -h, ls -la .cache/public).","Run gatsby clean to remove a possibly-corrupted .cache/public and retry.","If using avif/webp, rebuild sharp with codec support or fall back to jpg/png.","Reduce concurrent jobs / parallelism if multiple builds share the output dir.","Inspect err.message (surfaced in the error) to distinguish encoding vs. filesystem failure."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const fs = require('fs'); const path = require('path');\nfunction assertWritableOutput(outputPath) {\n  const dir = path.dirname(outputPath);\n  fs.ensureDirSync?.(dir); // if fs-extra available\n  const stat = fs.statSync(dir);\n  if (!stat.isDirectory()) throw new Error(`Output dir not a directory: ${dir}`);\n  fs.accessSync(dir, fs.constants.W_OK);\n}","typeGuard":"function isWritableDir(p) {\n  try { fs.accessSync(p, fs.constants.W_OK); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  await fs.writeFile(outputPath, buffer);\n} catch (err) {\n  if (err.code === 'ENOSPC') { reporter.panic('Out of disk space writing image output'); }\n  if (err.code === 'EACCES') { reporter.panic(`Permission denied: ${outputPath}`); }\n  throw err;\n}","preventionTips":["Monitor free disk space in CI; image builds are disk-heavy.","Ensure .cache and public are on writable volumes/mounts.","Confirm sharp supports your target format (avif/webp) before standardizing on it."],"tags":["gatsby-plugin-sharp","image-processing","filesystem","encode","disk"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}