Next.js Discord

Discord Forum

getStaticProps() is not running

Answered
Black Vulture posted this in #help-forum
Open in Discord
Avatar
Black VultureOP
I'm trying to grab props from a folder that I have the path to in my root directory. I'm certain that the json parsing is working fine and the helper functions are working fine (I can log them), but getStaticProps() is not able to pass it as a prop. This is my function:
export default function getStaticProps(){
    let allPostData = getSortedPostsData();
    console.log("Im useful!")
    return { props: { allPostData } }
}

And it's within a posts.ts file within a lib/ folder in my root directory. I have also tried running this from the page it is meant to support. Attached is a screenshot of the error I am receiving, and "Im useful!" is never logging. Logging the prop from the react page comes up as undefined as well.
Any help appreciated. Thanks in advance!
Image
Answered by Black Vulture
I tried it both ways. The answer seems to be that getStaticProps is no longer supported in the new app/ router and should be throwing an error except it just failed silently and never called it.
View full answer

6 Replies

Avatar
joulev
It is export function getStaticProps not export default function getStaticProps
Avatar
Black VultureOP
I tried it both ways. The answer seems to be that getStaticProps is no longer supported in the new app/ router and should be throwing an error except it just failed silently and never called it.
Answer
Avatar
Black VultureOP
Data fetching in the app router docs takes you here: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching
Avatar
joulev
Well that’s your error. In the app router it doesn’t exist so you can’t use it
You have to use server components as described in the linked page
Avatar
Black VultureOP
yep; I was reading the wrong docs. Didn't realize that anything besides routing changed.