#Sharp error (ERROR: A boolean was expected) ERROR: There was a problem while uploading the file.

3 messages · Page 1 of 1 (latest)

cloud rune
#

Media collection uploads are failing with the following error:

err: {
  "type": "TypeError",
  "message": "A boolean was expected",
  "stack":
      TypeError: A boolean was expected
          at /app/node_modules/sharp/lib/output.js:1612:15
          at new Promise (<anonymous>)
          at Sharp._pipeline (/app/node_modules/sharp/lib/output.js:1611:14)
          at Sharp.toBuffer (/app/node_modules/sharp/lib/output.js:164:15)
          at dj (/app/.next/server/chunks/8511.js:318:58899)
          at async R (/app/.next/server/chunks/8511.js:304:42526)
          at async a0 (/app/.next/server/chunks/8511.js:355:76583)
          at async q (/app/.next/server/app/(payload)/api/[...slug]/route.js:1:6204)
          at async /app/.next/server/app/(payload)/api/[...slug]/route.js:1:8853
          at async rb.do (/app/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:5:21059)
}
err: {
  "type": "g",
  "message": "There was a problem while uploading the file.",
  "stack":
      g: There was a problem while uploading the file.
          at dj (/app/.next/server/chunks/8511.js:318:61056)
          at async R (/app/.next/server/chunks/8511.js:304:42526)
          at async a0 (/app/.next/server/chunks/8511.js:355:76583)
  "data": null,
  "isOperational": true,
  "isPublic": true,
  "status": 400,
  "name": "g"
}

All other uploads (not using Sharp) are working.

cloud rune
#

Figured out the issue for my case. Posting to help others.

It seems like my Payload media collection sharp config was failing to be parsed (unchanged for long time):

  upload: {
    mimeTypes: ['image/*', 'video/*', 'audio/*'],
    // Use webp as preferred format for all media
    formatOptions: {
      format: 'webp',
      options: {
        lossless: true,
        effort: 6,
      },
    },
    // Upload to a public directory in Next.js making them publicly accessible even outside of Payload
    staticDir: path.resolve('public/uploads/media'),
  },

Culprit (as also mentioned on https://github.com/lovell/sharp/issues/4388) was that Sharp was resolving to multiple verisons.
Locally I saw:

  ❯ yarn why sharp
  ├─ mobeigi-com-app@workspace:.
  │  └─ sharp@npm:0.34.5 (via npm:0.34.5)
  │
  ├─ next@npm:15.4.11
  │  └─ sharp@npm:0.34.3 (via npm:^0.34.3)
  │
  └─ next@npm:15.4.11 [52d1f]
     └─ sharp@npm:0.34.3 (via npm:^0.34.3)

Solution was to resolve to right sharp version (long term maybe update Next.js to version that uses latest sharp version too):

  "resolutions": {
    "sharp": "0.34.5"
  },

This resolved the issue and I could upload to media collection using Sharp again.

Example PR on my own repo:
https://github.com/mobeigi/mobeigi.com/pull/315