Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
Nextjs getting build time error Cannot read properties of undefined

I am not getting any error when browsing page or url but when trying to npm run build getting this error Generating static pages (0/8)TypeError: Cannot read properties of undefined (reading 'blog_slug')

here is my full code:

I aslo want to show 404 page if dynamic url not exits. Right now I am getting this error for invalid url . I also set

if (res != 200) {
    return {
      notFound: true,
    };
  }

but didn't work. here is my full code:

export async function getStaticPaths() {
  const search_url = "https://backendapi.mydomain.com/blog-list/";
  const search_result = await fetch(search_url);
  const search_data = await search_result.json(search_result);
  const paths = search_data.map((data) => {
    return {
      params: {
        id: data.blog_slug,
      },
    };
  });
  return {
    paths,
    fallback: true, // false or 'blocking'
  };
}

export async function getStaticProps(context) {
  const id = context.params.id;
  const res = await fetch(`https://mydomain/blog-api/${id}`);
  const Blog = await res.json();
  const search_url = "https:/mydomain/blog-list/";
  const search_result = await fetch(search_url);
  const search_data = await search_result.json(search_result);

  if (res != 200) {
    return {
      notFound: true,
    };
  }

  return {
    props: {
      data: Blog,
      search_data: search_data,
    },
  };
}

here is my jsx look like:

function blog_details({ data, search_data }) {
      return (<h1>data.blog_slug<h1/)
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda