vercel/next.js · error · Error
Module `sharp` not found. Please run `npm install --cpu=wasm
Error message
Module `sharp` not found. Please run `npm install --cpu=wasm32 sharp` to install it.
What it means
Thrown by the image optimizer when require('sharp') throws MODULE_NOT_FOUND. Next.js uses sharp for server-side image optimization; when it is not installed (or only present for the wrong CPU), the catch block detects MODULE_NOT_FOUND and rethrows this actionable message instructing the wasm32 install. Any other require error is rethrown unchanged.
Source
Thrown at packages/next/src/server/image-optimizer.ts:121
'VipsForeignLoadTiff',
'VipsForeignLoadWebp',
],
})
if (typeof operationCache === 'boolean') {
_sharp.cache(operationCache)
}
if (_sharp.concurrency() > 1) {
// Reducing concurrency should reduce the memory usage too.
// We more aggressively reduce in dev but also reduce in prod.
// https://sharp.pixelplumbing.com/api-utility#concurrency
const divisor = process.env.NODE_ENV === 'development' ? 4 : 2
_sharp.concurrency(
concurrency ?? Math.floor(Math.max(_sharp.concurrency() / divisor, 1))
)
}
} catch (e: unknown) {
if (isError(e) && e.code === 'MODULE_NOT_FOUND') {
throw new Error(
'Module `sharp` not found. Please run `npm install --cpu=wasm32 sharp` to install it.'
)
}
throw e
}
return _sharp
}
export interface ImageParamsResult {
href: string
isAbsolute: boolean
isStatic: boolean
width: number
quality: number
mimeType: string
sizes: number[]
minimumCacheTTL: number
}View on GitHub (pinned to 0ae8c72462)
Solutions
- Run the command in the message: `npm install --cpu=wasm32 sharp` (or the package-manager equivalent).
- If you don't need optimization, disable it via images.unoptimized: true in next.config.
- For native performance on a supported platform, run `npm install sharp` to fetch the correct binary.
- After installing, restart the dev/prod server so sharp is required again.
Example fix
// before: next.config.js with optimization enabled but sharp missing
module.exports = {}
// after: either install sharp (`npm install --cpu=wasm32 sharp`) or disable optimization
module.exports = {
images: { unoptimized: true },
} Defensive patterns
Strategy: fallback
Validate before calling
// Detect missing sharp before the optimizer is hit; fall back to unoptimized
function resolveImagesConfig() {
try { require.resolve('sharp') } catch {
return { images: { unoptimized: true } } // graceful fallback
}
return { images: {} }
} Try / catch
try {
_sharp = require('sharp')
} catch (e: unknown) {
if (isError(e) && e.code === 'MODULE_NOT_FOUND') {
throw new Error('Module `sharp` not found. ...')
}
throw e
} Prevention
- Install sharp explicitly in production deps.
- Set images.unoptimized on platforms that can't run native sharp.
- Add a health check that require.resolve('sharp') succeeds in CI.
When it happens
Trigger: A request hits /_next/image (or the image optimizer) and sharp has not been installed. The require('sharp') at line 94 throws with code 'MODULE_NOT_FOUND', caught and converted to this message.
Common situations: Fresh install where sharp is an optional dependency that did not install. Deploying to a platform (e.g. wasm/edge or a minimal image) where the native sharp binary is unavailable. Using a package manager that skipped optionalDependencies. Manually removing sharp to slim node_modules.
Related errors
- It looks like you're trying to use TypeScript but do not hav
- It looks like you're trying to use Partytown with next/scrip
- Turbopack is not supported on this platform (${process.platf
- "url" parameter is not allowed
- "url" parameter is valid but upstream response timed out
AI-assisted analysis of vercel/next.js@0ae8c72462 (2026-08-06).
Data as JSON: /api/errors/08d7826b6e5d1d35.
Report an issue: GitHub.