'Why is getStaticProps not working on one specific server?
I tested this code on 2 servers and tried make it work on both.
On one Server there are no problems on the other there is nothing happening in getStaticProps not even the:
console.log('cards')
So I saw some one using getInitialProps but its recommended.
Is there an other option?
What did I destroy on the one server so that does not happen again?
If some one wants to read the code
import Image from 'next/image'
import styles from '../styles/Home.module.css'
export async function getStaticProps(){
console.log('cards')
const res = await fetch('http://localhost:1337/Cards')
const cards =await res.json()
console.log(cards)
return{
props:{
cards:cards
}
}
}
export default function Home({cards}) {
console.log(cards)
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<ul>
{cards.map((card)=>(
<li>{card.name}</li>
))}
</ul>
</div>
)
}
Solution 1:[1]
I am an Idiot because the file was a different folder called compontents now I am searching for a way to make my components right. So I know now that I should use the trouble shooting process to see more broadly on the server. I ask the question because some body esle had the same problem and the answer was use getInitialProps instead. Its recomend to not use it so thats why I ask. So my todo: Dont fall into a rabit hole while researching trouble shooting. And give more Information when you ask someone...
I hope the time you lost was not comletly lost and somebody has the same Problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Serching for meningful things |
