vercel/next.js · error · Error

Module `sharp` not found. Please run `npm install…

Error message

Module `sharp` not found. Please run `npm install --cpu=wasm32 sharp` to install it.

What it means

Thrown from readFromCacheDir when Next.js cannot load the sharp image processing library on a wasm32 target. The error surfaces from the catch of the sharp import/initialization and points the user at the wasm-specific install command; it means the runtime dependency for image optimization is simply absent.

Solutions

  1. Run npm install --cpu=wasm32 sharp to install the wasm build of sharp.
Defensive patterns

Strategy: fallback

When it happens

Trigger: The sharp module is required for image optimization but not installed.

Common situations: Running image optimization in an environment where sharp must be installed manually (e.g. wasm32).


AI-assisted analysis of vercel/next.js@996f957c06 (2026-08-19). Data as JSON: /api/errors/08d7826b6e5d1d35. Report an issue: GitHub.

Appendix: source

Thrown at packages/next/src/server/image-optimizer.ts:121

  }

  const dir = join(/* turbopackIgnore: true */ cacheDir, cacheKey)
  const filename = join(
    /* turbopackIgnore: true */
    dir,
    `${maxAge}.${expireAt}.${etag}.${upstreamEtag}.${extension}`
  )

  await promises.rm(dir, { recursive: true, force: true }).catch(() => {})

  await promises.mkdir(dir, { recursive: true })
  await promises.writeFile(filename, buffer)
}

async function readFromCacheDir(cacheDir: string, cacheKey: string) {
  const dir = join(/* turbopackIgnore: true */ cacheDir, cacheKey)
  const files = await promises.readdir(dir)
  const file = files[0]
  if (!file) {
    throw new Error(
      `Invariant: cache entry "${cacheKey}" not found in dir "${cacheDir}"`
    )
  }
  const [maxAgeSt, expireAtSt, etag, upstreamEtag, extension] = file.split(
    '.',
    5
  )
  const filePath = join(/* turbopackIgnore: true */ dir, file)
  const buffer = await promises.readFile(/* turbopackIgnore: true */ filePath)
  if (buffer.byteLength === 0) {
    throw new Error(`Invariant: image cache entry "${cacheKey}" is empty`)
  }
  const expireAt = Number(expireAtSt)
  const maxAge = Number(maxAgeSt)
  return { maxAge, expireAt, etag, upstreamEtag, buffer, extension }
}

View on GitHub (pinned to 996f957c06)