Error: The reference 'GetServerSideProps' is being incorrectly used as a type instead of a value. Perhaps you intended to use 'typeof GetServerSideProps' instead?

Index.tsx

import Image from 'next/image'
import Head  from "next/head"
import { sanityClient, urlFor  } from "../sanity"
import Link from 'next/link'
import {Collection, address} from '../typings';
import  GetServerSideProps  from 'next';

interface props {
  collections: Collection

}

const Home=({collections}: props) => {
  return (

    
  <div className='bg-yellow-400 max-auto  flex min-h-screen flex-col py-10 px-10 '>
      <Head>
        <title>Ordinal Cats</title>
        <link rel="stylesheet" href="/fevicon.ico" />
      </Head>

      
        <h1 className='w-52 text-xl font-extralight sm:w-80 py-5'>
          <span className='font-extrabold underline decoration-orange-600/50'>Ordinal Cats</span>
        </h1>        
   

      <main className='bg-orange-500 rounded-lg p-10 shadow-xl shadow-black items-center ' >
        <div className='grid space-x-3 md:grid-cols-1 lg:grid-cols-1 2xl:grid-cols-4'>
          {collections?.map(collection => (

            
            <div key={collection.slug.current} className='flex flex-col items-center'>
              <img className='h-70 w-50 rounded-2xl object-cover' src={urlFor(collection.mainImage).url()} alt="" />
            <div>
            <h2 className='text-3xl items-center text-center'>{collection.title}</h2>
            <p className='mt-2 text-sm text-white text-center'>{collection.description}</p>
            <Link href={`${collection.slug.current}`} >
            <button className='cursor-pointer transition-all duration-200 hover:scale-105 h-16 bg-[#facf38] w-full text-Black rounded-full mt-2 font-bold disabled:bg-gray-400'>Mint</button>
            </Link>
            </div>
            </div>
            
          ))}
        </div>
      </main>
    </div>


  )
}

export default Home

export const  GetServerSideProps = async () => {
  const query = `*[_type == "collection"]{
    _id,
      title,
      address,
      description,
      nftCollectionName,
      mainImage{
      asset
      },
    previewImage {
      asset
    },
    slug {
      current
    },
    creator -> {
      _id,
      name,
      address,
      slug{
        current
      },
    },
  }`

  const collections = await sanityClient.fetch(query)

  return{
    props: {
      collections
    }
  }
  
}


enter image description here

My Backend File // typings.d.ts

interface Image{
    asset: {
        url: string
    }
}

export interface Creator {
    _id:string
    name:string
    address:string
    slug:{
        current:string
    }
    image:Image
    bio:string
}

export interface Collection {
    _id:string
    title:string
    description:string
    nftCollectionName:string
    address:string
    slug:{
        current:string
    }
    creator:Creator
    mainImage:Image
    previewImage:Image
}

Everything is working in my local environment without any issues. However, when I try to deploy the project on Vercel by running 'npm run build', it encounters multiple errors and exits with code 1. I have attempted to remove node modules and reinstall packages, but the issue persists. Any assistance would be greatly appreciated.

I am trying to successfully deploy my project on a hosting platform like Vercel. While the code functions flawlessly locally, deployment is met with errors that prevent successful hosting. Your help in resolving these errors would be invaluable to me.

Answer №1

When utilizing GetServerSideProps
, remember that it should be structured as getServerSideProps

Ensure your function is constructed in the following format:

export const getServerSideProps: GetServerSideProps = async (context) => {
  // ...
}

For more information, refer to the typescript docs here

PS. It can be a bit confusing at first, but with practice, it becomes clearer.

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

What is the proper way to create a React Context in TypeScript that accepts both a ref and a setState function as arguments?

When encountering various errors, one of them being: Type 'Dispatch<SetStateAction<null>>' is not assignable to type '() => void' My code looks something like this: import React, { ReactElement, ReactNode, useEffec ...

Dealing with side effects in react/redux: Best practices and tips

Trying to find the best way to integrate an async side-effects handler into my react/redux setup has been quite a challenge. In my react-router-driven application, all the main containers at root level are smoothly dispatching actions and receiving update ...

Deactivate the underscore and include the fiscal year in AngularJS

I am currently faced with a scenario where the back end is returning the value as follows: 123222_D1.123 However, I need to display the date from the database (12-Jun-2020) as 2020-D1.123 in a drop-down menu. Currently, I am displaying the above value i ...

What is the proper method to deactivate a hyperlink in Angular 2?

I'm currently developing a web application using Angular2, and I find myself in need of displaying, but making it non-clickable, an <a> element within my HTML. Can anyone guide me on the correct approach to achieve this? Update: Please take no ...

Discover the process of translating words within app.routing.module.ts in Angular

Having some trouble with my Angular routing module and ngx-translate languages. I'm trying to retrieve words from the languages in this module, but the code I've attempted isn't working: import { NgModule } from '@angular/core'; im ...

Is it possible to verify if a function is invoked using Jest, Typescript, and ts-jest in action?

Currently, I'm testing the functionality of this code snippet: src/helpers/CommentHelper.ts: export default class CommentHelper { gitApiObject: GitApi.IGitApi ; constructor(gitApiObject: GitApi.IGitApi) { this.gitApiObject = gi ...

The parameter 'host: string | undefined; user: string | undefined' does not match the expected type 'string | ConnectionConfig' and cannot be assigned

My attempt to establish a connection to an AWS MySQL database looks like this: const config = { host: process.env.RDS_HOSTNAME, user: process.env.RDS_USERNAME, password: process.env.RDS_PASSWORD, port: 3306, database: process.env.RDS_DB_NAME, } ...

Typescript counterpart of a collection of key-value pairs with string keys and string values

Within the API I'm currently working with, the response utilizes a data type of List<KeyValuePair<string, string>> in C#. The structure appears as shown below: "MetaData": [ { "key": "Name", &q ...

The HTTP post method in Angular 2 fails to properly send data to request.JSON within a Grails Action

Having trouble retrieving data from request.JSON passed through an Angular 2 HTTP POST method. The Grails action is being triggered, but the request.JSON is consistently empty {} even when data is passed. ANGULAR2: HTTP POST Method: return this.http.pos ...

Improving DynamoDb Query Results with Type Hinting

In the following Typescript code, how can I specify which fields should be present in my Query Items Result? const request: DynamoDB.DocumentClient.QueryInput = { TableName: UnsubscriptionTokensRepository.TABLE_NAME, IndexName: 'TokenIndex&ap ...

What is the best way to retrieve certain fields from a Firestore database using Next.js?

Is there a way to access a specific field in a document using the user's uid as its name? I am utilizing useAuthState from react-firebase-hooks to retrieve the user's credentials (uid). This code snippet allows me to console log all the document ...

Troubleshooting issues with accessing the _id property using Typescript in an Angular application

Encountering an Angular error that states: src/app/components/employee/employee.component.html:67:92 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is ...

Determining Refresh Status in Angular Application

Does Angular provide a method to determine if the browser has been refreshed? I need to verify whether the page has been refreshed or not, as I want to run a function only when the value is false. In my ngOnInit function, I have the following code: pageIs ...

Using Angular 2, you can pass an object as a parameter to a function

Is there a way to pass an object as a parameter in the DOM on this forum? Within my HTML code, I have the following: <div class="list-items"> <ul> <li *ngFor="let i of item"> <span (click)="onAdd({{newUser.us ...

Despite encountering the 'property x does not exist on type y' error for Mongoose, it continues to function properly

When working with Mongoose, I encountered the error TS2339: Property 'highTemp' does not exist on type 'Location' when using dot notation (model.attribute). Interestingly, the code still functions as intended. I found a solution in the ...

TS1057: It is required that an async function or method has a return type that can be awaited

There was a recent Github issue reported on March 28th regarding async arrow functions generating faulty code when targeting ES5, resulting in the error message: TS1057: An async function or method must have a valid awaitable return type You can find t ...

Having trouble with JSON parsing in Promise execution

I am in the process of developing a Promise with the objective of adding up any numbers discovered within an array or JSON object. The add() function is designed to receive a series of URLs as a string input and calculate the total sum of those URLs. Her ...

I have the ability to see HTTP-only cookies within my web browser

So, I always believed that httpOnly cookies could only be accessed during a http request. But the other day, while inspecting Firefox dev tools, I noticed that I could actually view the cookies' values. Is this standard behavior? ...

Challenges with deploying Next.js and Express with Zeit Now

I recently developed a SSR Next.js webpage with an attached Express server for handling email functionalities related to a contact form. After deploying the project on now, I encountered a 502 error when making network requests to my Express server despit ...

The JavaScript code is executing before the SPFX Web Part has finished loading on the SharePoint page

I recently set up a Sharepoint Page with a custom masterpage, where I deployed my SPFx Webpart that requires certain javascript files. While the Webpart functions correctly at times, there are instances when it doesn't work due to the javascript bein ...