Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  146] [ 2]  / answers: 1 / hits: 12525  / 2 Years ago, mon, december 27, 2021, 12:00:00

when I want to export my nextjs app, it says that I cannot export my images on static websites.



Error: Image Optimization using Next.js' default loader is not compatible with next export.
Possible solutions:
- Use next start to run a server, which includes the Image Optimization API.
- Use any provider which supports Image Optimization (like Vercel).
- Configure a third-party loader in next.config.js.
- Use the loader prop for next/image.



How can I make it so that it does ?


Is there a way for me to simply tell it to render images statically ? I dont want to go throught other onlines images loaders..


More From » next.js

 Answers
0

You need to set up a custom image loader in Next.js


In your next.config.js file, add this property to the export:


images: {
loader: "custom"
}



And make a script called loader.js that exports this:


function imageLoader({ src }) {
return `/images/${src}`; // REPLACE WITH YOUR IMAGE DIRECTORY
}

module.exports = imageLoader;



For each Image component, set the loader prop manually:


const imageLoader = require("PATH TO loader.js");

<Image loader={imageLoader} />

[#554] Thursday, December 16, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shekinah

Total Points: 699
Total Questions: 112
Total Answers: 110

Location: Philippines
Member since Sat, Jul 11, 2020
4 Years ago
shekinah questions
Tue, Apr 6, 21, 00:00, 3 Years ago
Mon, Dec 28, 20, 00:00, 3 Years ago
Fri, Oct 23, 20, 00:00, 4 Years ago
;