AVIF images get green tint after upgrading Next.js (prod only) – sharp already installed #88425
Replies: 1 comment
-
|
This green tint issue with AVIF images in production is a libvips color profile handling bug that affects specific sharp/libvips version combinations on certain platforms. Root CauseThe issue stems from:
SolutionsSolution 1: Pin Sharp Version (Recommended)Downgrade to a known-working sharp version: {
"dependencies": {
"sharp": "0.33.5"
},
"overrides": {
"sharp": "0.33.5"
}
}Then: rm -rf node_modules package-lock.json
npm installSolution 2: Force Rebuild Sharp in ProductionEnsure sharp uses platform-specific binaries: Option A - Using npm scripts: {
"scripts": {
"build": "npm rebuild sharp && next build"
}
}Option B - In your Dockerfile (if using Docker): FROM node:20-alpine
# Install libvips dependencies
RUN apk add --no-cache \
libvips-dev \
build-base \
python3
WORKDIR /app
COPY package*.json ./
RUN npm ci
RUN npm rebuild sharp
COPY . .
RUN npm run buildSolution 3: Disable AVIF in next.config.jsTemporary workaround - use WebP instead: /** @type {import('next').NextConfig} */
module.exports = {
images: {
formats: ['image/webp'], // Remove AVIF
},
};Solution 4: Force Specific Sharp ConfigCreate a custom image loader that handles color spaces explicitly: // next.config.js
module.exports = {
images: {
loader: 'custom',
loaderFile: './imageLoader.js',
},
};// imageLoader.js
export default function imageLoader({ src, width, quality }) {
return `/_next/image?url=${encodeURIComponent(src)}&w=${width}&q=${quality || 75}`;
}Solution 5: Update Environment VariablesSet these in your AWS deployment: SHARP_IGNORE_GLOBAL_LIBVIPS=1
SHARP_FORCE_GLOBAL_LIBVIPS=0This forces sharp to use its bundled libvips rather than system-installed versions. Best Practice FixFor AWS Lambda/Serverless: {
"dependencies": {
"sharp": "0.33.5"
},
"devDependencies": {
"@img/sharp-linux-x64": "0.33.5"
}
}For AWS EC2/ECS: npm install --platform=linux --arch=x64 sharpWhy This HappensNext.js 16.1.1 updated its image optimization dependencies, which changed how sharp/libvips handles AVIF color spaces. The green tint specifically indicates YUV to RGB conversion issues where the chroma channels are misinterpreted. Debugging Steps
node -e "console.log(require('sharp').versions)"
# Local
node -e "console.log(process.platform, process.arch)"
# Should match your production environmentRelated IssuesThe Next.js team is aware of this and working on better cross-platform compatibility for image optimization. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hi everyone 👋
After upgrading a Next.js version
AVIF images rendered with
next/imageshow a green tint in production (AWS).What is the recommended solution for this?
When I tried to find resources explaining how next/image optimization works internally, I couldn’t find any clear or helpful documentation. Can someone please share a good resource or explanation?
Additional information
Example
Beta Was this translation helpful? Give feedback.
All reactions