I am attempting to pre-render 2000+ pages for all company ticker symbols in the code below:
export async function getStaticPaths() {
//fetch all company symbols available in this financialmodelingprep API (> 2000)
const res = await fetch(
"https://financialmodelingprep.com/api/v3/stock/list?apikey=asecret"
);
const AllCompanies = await res.json();
//reduce array to observe that smaller arrays prerender more successfully
const paths = AllCompanies.slice(0, 600).map((ticker) => {
return {
params: { id: ticker.symbol },
};
});
return {
paths,
fallback: false,
};
}
export async function getStaticProps(context) {
//fetch company news data based on getStaticPaths params
const res = await fetch(
`https://financialmodelingprep.com/api/v3/stock_news?tickers=${context.params.id}&limit=50&apikey=asecret`
);
const newsData = await res.json();
return {
props: { newsData: newsData },
};
}
const CompanyPage = ({ newsData }) => {
return (
<>
<div>{newsData[0].symbol}</div>
<div>{newsData[0].publishedDate}</div>
<div>{newsData[0].title}</div>
</>
);
};
export default CompanyPage;
Where the getStaticPaths' API response format is:
[
{
"symbol": "SPY",
"name": "SPDR S&P 500 ETF Trust",
"price": 422.6,
"exchange": "New York Stock Exchange Arca"
},
{
"symbol": "CMCSA",
"name": "Comcast Corporation",
"price": 57,
"exchange": "Nasdaq Global Select"
},
...
]
The error I get is always similar to:
[=== ] info - Generating static pages (453/604)
Error occurred prerendering page "/company/TOPS". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read property 'symbol' of undefined
at CompanyPage (C:\Users\Jake Arsement\rps\simple-markets-next\.next\server\pages\company\[id].js:54:29)
> Build error occurred
Error: Export encountered errors on following paths:
/company/MON
/company/TOPS
/company/WY
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! simple-markets-next@0.1.0 build: `next build`
npm ERR! Exit status 1
Where failing paths vary each time I execute 'npm run build'.
It seems like Next is having trouble with the amount of paths when above ~300, as I've checked to ensure there is a 'symbol' property for the failing paths. I'm wondering if there is some path array size limitation. I could not find any mention of a limit in the docs. Any help is gratefully appreciated.