简体   繁体   English

getStaticPaths array.map 在部署到 Vercel 时不是 function

[英]getStaticPaths array.map isn't a function when deploying to Vercel

Code is below, the dev server works perfectly fine without error, however when I try to deploy the site I get this error.代码如下,开发服务器工作正常,没有错误,但是当我尝试部署站点时出现此错误。

> Build error occurred
TypeError: artists.map is not a function
    at getStaticPaths (/vercel/path0/.next/server/pages/artists/[slug].js:106:24)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async buildStaticPaths (/vercel/path0/node_modules/next/dist/build/utils.js:498:31)
    at async /vercel/path0/node_modules/next/dist/build/utils.js:641:119
    at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:74:20) {
  type: 'TypeError'
}
export async function getStaticProps({ params }) {
  const siteSettings = await fetcher("http://localhost:3000/api/settings");
  const artists = await fetcher(
    `${process.env.URL}/api/artists/${params.slug}`
  );
  const artist = artists.allArtist[0];

  return {    
    props: {    
      siteSettings,    
      artist,    
    },    
  };    
} 

export async function getStaticPaths() {    
  const artists = await fetch(`${process.env.URL}/api/artists`);    
     
  return {                                                                                                           
    paths: artists.map((artist) => {                                                                                 
      return {    
        params: {    
          slug: artist.slug.current,    
        },    
      };    
    }),    
    fallback: false,    
  };    
}    

How would I go about fixing this error, as I said it works perfectly fine in the dev server with no console logs containing any errors.我将如何解决此错误,因为我说它在开发服务器中运行良好,没有包含任何错误的控制台日志。

Any help would be greatly appreciated.任何帮助将不胜感激。

I attempted writing the API route logic directly in the getStaticProps function and this fixed the error @juliomalves also posted this link which suggests a similar answer: Fetch error when building Next.js static website in production I attempted writing the API route logic directly in the getStaticProps function and this fixed the error @juliomalves also posted this link which suggests a similar answer: Fetch error when building Next.js static website in production

Thanks for the help.谢谢您的帮助。

Mac苹果电脑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM