0

I am create a next build with standalone output. I follow this answer- How to deploy NextJs (SSR) using "Output File Tracing" feature to Azure App Service?

After setting up I run my server like this node server.js

It works perfectly. But here image optimization not working. I found one error-

Error: 'sharp' is required to be installed in standalone mode for the image optimization to function correctly

I recheck package.json and I can see sharp is already installed. Then I add this to my .env file- NEXT_SHARP_PATH=/tmp/node_modules/sharp

But not working. Please any help me. I need image opmization feature in standalone mood.

***Note: I use linux subsystem on windows. In linux subsystem, When I run production mode npm run start. Image optmization automatically work in this mode, I haven't to give .env also. When I start my project in standalone mood, image optimization is not working. Even when I give .env it's not working.

Here is my next.config.js-

/** @type {import('next').NextConfig} */
const withPWA = require("next-pwa")({
  dest: "public",
  register: true,
  disable: process.env.NODE_ENV === "development"
});

const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  output: "standalone",
  images: {
    minimumCacheTTL: 2592000,
    domains: ["dzzoo94ozikw5.cloudfront.net", "lh3.googleusercontent.com", "platform-lookaside.fbsbx.com"]
  },
}

module.exports = withPWA(nextConfig)

1
  • 1
    For anyone that don't use the latest Next.js, use this in Dockerfile: RUN yarn add [email protected] --ignore-engines. Specifying this specific older sharp version solves the problem. Commented May 21, 2024 at 9:38

1 Answer 1

0
yarn add sharp

or

npm install sharp

https://nextjs.org/docs/messages/sharp-missing-in-production

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.