7

This is my code for the Nextjs Image component:

...  Cell: ({ value }: CellType) => (
  <Image
    priority
    src={value}
    loader={() => value}
    className={''}
    height={100}
    width={100}
    alt={'profile_picture'}
  />
),

enter image description here

Does it mean I need a custom loader function to get rid off the warning? Thanks!

2
  • 3
    If you're not applying any optimisations through a 3rd party cloud provider (your loader isn't doing anything), you might as well just use unoptimized={true} on the Image. Commented Feb 20, 2022 at 16:13
  • @juliomalves that actually makes sense. Thank you! I'll update my Q! Commented Feb 20, 2022 at 18:56

3 Answers 3

10

I had a same issue like yours and solved by adding unoptimized={true} prop into the <Image> tag. If you don't apply optimizations, you need to announce that you don't optimize.
Something like below:

<Image
    priority
    src={value}
    loader={() => value}
    unoptimized={true}  // <=== insert this prop
    className={''}
    height={100}
    width={100}
    alt={'profile_picture'}
  />

Please let me know if it work.
Thank you.

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

Comments

3

I had the same error but what I have done to fix it is to incorporate in the next.config.js file the URL of my media files, in my case it is cloudinary, the file should look like this:


/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,

  images: {
    domains: [
      'res.cloudinary.com'
    ],
  },
}

module.exports = nextConfig

And when I use the image component (next/image) I remove the loader and just put the URL like this:

<Image
  key={element.id}
  src={element.url}
  width={500}
  height={500}
  alt="some description"
/>

I don't use unoptimized={true} because the point is that the component changes the quality of the image according to the client's device.

good look :)

Comments

3

I fixed it like this:

Added this definition to loader attribute-:

loader={({ src, width }) => { return src + "?w=" + width }}

<Image
    priority
    src={value}
    loader={({ src, width }) => { return src + "?w=" + width }}
    height={100}
    width={100}
    alt={'profile_picture'}
/>

1 Comment

Do note that some external URLs might return an error if you add ?w= to the query string when they're very strict. For example, an URL that has the image specified in the query string itself, e.g. foo.com/image?image_hash=asdfasdf

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.