Next.js searches images in local directory not on AWS

Viewed 1170

We are converting our app to Next.js from Create React App.

Next.js should load images from AWS but this not happen. Why?

It worked some days ago. Do you think it's some caching problems or what?

Do you any ideas?

In Next.js the app loads the images from this local URL:

http://localhost:3000/_next/image?url=https%3A%2F%2Fticket-t01.s3.eu-central-1.amazonaws.com%2Fob8h_0.cover.jpg&w=1200&q=100

next.config.js:

const { nextI18NextRewrites } = require("next-i18next/rewrites");

const localeSubpaths = {
  hu: "hu",
  en: "en"
};

module.exports = {
  rewrites: async () => nextI18NextRewrites(localeSubpaths),
  publicRuntimeConfig: {
    localeSubpaths
  },
  images: {
    domains: ["ticket-t01.s3.eu-central-1.amazonaws.com"]
  }
};

1 Image tag:

<Image
  src={`https://ticket-t01.s3.eu-central-1.amazonaws.com/${props.imgId}_0.cover.jpg`}
  className={styles.imageEventMain}
  alt="main event"
  layout="responsive"
  width={1795}
  height={1000}
  quality={100}
/>;

In React there wasn't problems with AWS or image loading.

EDIT

console.log when trying to access the images:

enter image description here

1 Answers

I managed to solve this:

Change:

module.exports = {
  rewrites: async () => nextI18NextRewrites(localeSubpaths),
  publicRuntimeConfig: {
    localeSubpaths
  },
  images: {
    domains: ["ticket-t01.s3.eu-central-1.amazonaws.com"]
  }
};

To:

module.exports = {
  rewrites: async () => nextI18NextRewrites(localeSubpaths),
  publicRuntimeConfig: {
    localeSubpaths
  },
  images: {
    loader: "imgix",
    path: "https://ticket-t01.s3.eu-central-1.amazonaws.com/",
    domains: ["ticket-t01.s3.eu-central-1.amazonaws.com"]
  }
};

Change your Image component like this:

<Image
  src={`${props.imgId}_0.cover.jpg`}
  className={styles.imageEventMain}
  alt="main event"
  layout="responsive"
  width={1795}
  height={1000}
  quality={100}
/>;

This should do the trick!

Related