2

This is my function to get a path will be run in local dev mode

export async function getStaticPaths(){
    const datas = await fetch(`https://mydomain.vercel.app/api/annonces/annonces`)
    const annonces = await datas.json()

    const paths = annonces.map(item =>({
        params: {annonce: item._id}
    }))

    return {
        paths,
        fallback: false
    }
}

This is my error when I deploy my app

> Build error occurred
SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
0

1 Answer 1

1

Got the same error while deployment. I think it has to do with calling API routes created by nextjs in getStaticPaths and getStaticProps. Got it resolved after moving the api code to getStaticPaths and getStaticProps.

As per the documentation "This means that instead of fetching an API route from getStaticProps (that itself fetches data from an external source), you can write the server-side code directly in getStaticProps."

write-server-side-code-directly

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

1 Comment

Really thanks ! Is Exactly this problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.