There is no imageURL property available for this type

Everything was running smoothly on my local project, but encountered errors upon deploying to Vercel:

The properties imageURL and alt do not exist on type {}

Despite attempting to define the types based on suggestions from Stack Overflow, the issues persist.

I am utilizing Sanity as a CMS for fetching images to display on the front end.

import React from "react";
import leftarrow from "../public/arrowleft.png";
import rightarrow from "../public/arrowright.png";

interface Image {
  imageUrl: any;
  alt: any;
}

export default function GalleryBlock({ images }: any) {
  const [currentIndex, setCurrentIndex] = React.useState(0);
  let initialPosition: number | undefined;
  let finalPosition: number | undefined;

  const decreaseIndex = () => {
    let prev = currentIndex == 0 ? images.length - 1 : currentIndex - 1;
    document.getElementById(`image-${currentIndex}`)!.style.opacity = "0";
    document.getElementById(`image-${prev}`)!.style.opacity = "1";
    setCurrentIndex(prev);
  };

  const increaseIndex = () => {
    let next = currentIndex == images.length - 1 ? 0 : currentIndex + 1;
    document.getElementById(`image-${currentIndex}`)!.style.opacity = "0";
    document.getElementById(`image-${next}`)!.style.opacity = "1";
    setCurrentIndex(next);
  };

  const changeToImage = (index: number) => {
    document.getElementById(`image-${currentIndex}`)!.style.opacity = "0";
    document.getElementById(`image-${index}`)!.style.opacity = "1";
    setCurrentIndex(index);
  };

  const swipeMove = () => {
    if (initialPosition !== undefined && finalPosition !== undefined) {
      if (finalPosition - initialPosition > 30) {
        decreaseIndex();
        initialPosition = undefined;
        finalPosition = undefined;
      } else if (initialPosition - finalPosition > 30) {
        increaseIndex();
        initialPosition = undefined;
        finalPosition = undefined;
      }
    }
  };

  return images.length > 0 ? (
    <div>
      <div className="flex px-[20px] pt-[20px] mb-[40px] md:px-[50px]">
        <div
          className={"hidden items-center text-center cursor-pointer sm:flex"}
          onClick={() => decreaseIndex()}
        >
          <img src={leftarrow.src} width={50} />
        </div>
        <div
          className={"w-full h-[500px] relative mx-[10px]"}
          onTouchStart={(e) => {
            initialPosition = e.touches[0].clientX;
          }}
          onTouchEnd={(e) => {
            finalPosition = e.changedTouches[0].clientX;
            swipeMove();
          }}
        >
          <img
            id={"image-0"}
            className={
              "absolute inset-x-1/2 transform -translate-x-1/2 inset-y-1/2 -translate-y-1/2 transition-opacity duration-1000 max-w-full max-h-full"
            }
            src={images[0].imageUrl}
            alt={images[0].alt}
          />
          {images.map((image: {}, index: number) =>
            index == 0 ? (
              ""
            ) : (
              <img
                key={index}
                className={
                  "absolute inset-x-1/2 transform -translate-x-1/2 inset-y-1/2 -translate-y-1/2 max-h-full max-w-full transition-opacity duration-1000"
                }
                style={{ opacity: "0" }}
                id={`image-${index}`}
                src={image.imageUrl}
                alt={image.alt}
              />
            )
          )}
        </div>
        <div
          className={"hidden items-center text-center cursor-pointer sm:flex"}
          onClick={() => increaseIndex()}
        >
          <img src={rightarrow.src} width={50} />
        </div>
      </div>
      <div
        className={
          "w-full h-[60px] flex justify-center sm:h-[80px] md:h-[100px]"
        }
      >
        <div className={"flex p-[10px]"}>
          <div
            className={"flex items-center text-center cursor-pointer mr-[10px]"}
            onClick={() => decreaseIndex()}
          >
            <img src={leftarrow.src} width={30} />
          </div>
          <div className={"flex"}>
            {(currentIndex > 1
              ? images.slice(currentIndex - 2, currentIndex)
              : images
                  .slice(images.length - 2 + currentIndex)
                  .concat(images.slice(0, currentIndex))
            ).map((image: {}, index: number) =>
              currentIndex == images.indexOf(image) ? (
                ""
              ) : (
                <img
                  key={index}
                  className={"max-h-full mx-[5px] cursor-pointer"}
                  onClick={() => changeToImage(images.indexOf(image))}
                  src={image.imageUrl}
                  alt={image.alt}
                />
              )
            )}
          </div>
          <div>
            <img
              className={"max-h-full mx-[5px] cursor-pointer"}
              style={{ outline: "solid silver 3px" }}
              src={images[currentIndex].imageUrl}
              alt={images[currentIndex].alt}
            />
          </div>
          <div className={"flex"}>
            {(currentIndex < images.length - 2
              ? images.slice(currentIndex + 1, currentIndex + 3)
              : images
                  .slice(currentIndex + 1, images.length)
                  .concat(images.slice(0, currentIndex - images.length + 3))
            ).map((image: {}, index: number) =>
              currentIndex == images.indexOf(image) ? (
                ""
              ) : (
                <img
                  key={index}
                  className={"max-h-full mx-[5px] cursor-pointer"}
                  onClick={() => changeToImage(images.indexOf(image))}
                  src={image.imageUrl}
                  alt={image.alt}
                />
              )
            )}
          </div>

          <div
            className={"flex items-center text-center cursor-pointer ml-[10px]"}
            onClick={() => increaseIndex()}
          >
            <img src={rightarrow.src} width={30} />
          </div>
        </div>
      </div>
    </div>
  ) : (
    <div />
  );
}

Answer №1

There are a couple instances where you're using

.map((image: {}, index: number) => ... )
. It seems like you're destructuring the image into an empty object without using any of its values. You could try switching it to the following, which might be more helpful: .map((image, index) => ... )

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error Encountered: RSA Key Pairs Invalid Signature for JSON Web Token (JWT)

I am facing an issue with my Node.js application (version 20.5.1) regarding the verification of JSON Web Tokens (JWT) using RSA key pairs. The specific error message I am encountering is: [16:39:56.959] FATAL (26460): invalid signature err: { "type& ...

Having difficulty refreshing metadata on the client side within Next.js through client-side data retrieval

Having some trouble with updating metadata using NextSeo when fetching data on the client side. useEffect(()=>{ fetch(assetURL) .then((res) => res.json()) .then((data) => { console.log(data); }) .catch((error) => { console.err ...

The integration of Paystack payment is operating smoothly, however, there is a 404 error being returned from the PUT API in

I am facing an issue with integrating paystack into my ecommerce website. Despite troubleshooting extensively, I cannot locate the source of the errors that are occurring. The integration of other payment platforms is successful, but paystack is causing pr ...

How can I capture the click event on the oktext in Ionic?

When using Ionic, I have a select button with options for okText and cancelText. The issue I am facing is that when I click on okText, the menu closes as expected due to this attribute. However, I am interested in implementing it through click events. Belo ...

Troubleshooting issue with GetStaticProps function in NextJs

Recently, I've configured a project using NextJs along with WordPress Headless CMS, WP GraphQL, and ACF. One of the challenges I faced was retrieving the Image URL from its ID when calling attributes through WP GraphQL. To address this issue, I utili ...

Enhancing SEO with nextJs ServerSideProps for optimized HTML rendering

Having an issue with rendering HTML output in AG-Grid using NextJS getServerSideProps. When checking the source code, the rendered HTML is not there for SEO purposes. However, if I output the "staff" array to a div, then the HTML is visible in the source ...

Aggregating all elements in an array to generate a Paypal order

I'm currently working on a React project where I need to integrate the PayPal order function and include every item from an array. Below is my code snippet, but I'm struggling with how to achieve this: export default function Cart(): JSX.Element ...

Send the function to the directive

Below is the code for a directive: module app.directives { interface IDmDeleteIconController { doAction(): void; } class DmDeleteIconController implements IDmDeleteIconController { static $inject = ['$scope']; ...

Create individual account pages with specific URLs in Next.js

I'm currently working on developing a website that will feature individual user pages showcasing their posts and additional information. I'm facing some difficulty in figuring out how to generate new links to access these user accounts. For insta ...

CORS is preventing access to the XMLHttpRequest

My backend is powered by Vapor and front end uses Next.js on Ubuntu. I am trying to access the database using this code snippet: let cq = { text: "My question", }; axios({ method: "post", url: `http://loca ...

show additional worth on the console

Just starting out with JavaScript. Trying to display additional values in the console. Uncertain about how to access add-ons. Can anyone help me troubleshoot? Here is my code snippet below: https://jsfiddle.net/6f8upe80/ private sports: any = { ...

How can I append a query parameter to the URL in NextJS?

My goal is to include a query parameter whenever I enter some text in an input field and press the ENTER key. However, I'm struggling to determine the correct placement for this query parameter to function properly. Essentially, I want my URL to show ...

What is the best way to retrieve all values stored within a string enum?

Looking to retrieve all values from a string enum. For example, in the following enum, I want to extract ["Red", "Yellow"]: export enum FruitColors { Apple = "Red", Banana = "Yellow", } ...

Exploring the various form types supported by 'react-hook-form'

I utilized react hooks form to create this form: import React from "react"; import ReactDOM from "react-dom"; import { useForm, SubmitHandler } from "react-hook-form"; import "./styles.css"; function App() { type ...

Error retrieving data: The JSON response was invalid, as an unexpected token `<` was found at the beginning of the response. This issue occurred while using

Utilizing the getStaticProps and getStaticPaths functions, I made a fetch API call to an API endpoint (specifically a Wordpress headless CMS) in order to set dynamic routing paths. While running npm dev, everything functions correctly as the data is succes ...

Using material-ui styled components in Next.js server components can greatly enhance the appearance and functionality of your

I am currently working with Next.js version 14 and the app router in conjunction with Material-UI v5. Rendering Material-UI components in server pages components works perfectly fine for me. However, I run into an issue when trying to style these componen ...

Testing React Hooks in TypeScript with Jest and @testing-library/react-hooks

I have a unique custom hook designed to manage the toggling of a product id using a boolean value and toggle function as returns. As I attempt to write a unit test for it following a non-typescripted example, I encountered type-mismatch errors that I' ...

There is a problem with the "loader" property in Next.js Image that is causing width implementation issues

Here is my implementation of the Next.js Image component: ... Cell: ({ value }: CellType) => ( <Image priority src={value} loader={() => value} className={''} height={100} width={100} alt={'profile_pic ...

Is there a way to create a type interface that points to the structure of another type?

I am focused on developing a type interface that includes properties defined in another interface. Below is the schema definition for a model object in TypeScript: export interface ModelSchema { idAttribute: string; name: string; attributes: { ...

What is the best way to incorporate a react component into a Next.js project?

Looking to integrate a date picker that can select dates and ranges for my nextJS project, but struggling with adding components based on the online code. After running npm install react-day-picker --save, I came across this code: import React from ' ...