Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

590
Views
Error de Next.js al serializar `resultados` devueltos por `getServerSideProps`

Estoy trabajando con Next.js tratando de getServerSIdeProps y obteniendo este error:

Error: Error al serializar .results devueltos desde getServerSideProps en "/". Motivo: undefined no se puede serializar como JSON. Utilice null u omita este valor.

 export async function getServerSideProps(context) { const genre = context.query.genre; const request = await fetch( `https://api.themoviedb.org/3${ requests[genre]?.url || requests.fetchTrending.url }` ).then((res) => res.json()); return { props: { results: request.results, }, }; }

Estaba funcionando ayer, pero hoy recibo este error. ¿Podría alguien por favor ayudarme?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

al convertir sus datos a JSON, se produjo un error porque el valor undefined no se puede serializar, en otras palabras, no puede convertir objetos con indefinido como el valor de una de sus propiedades en json.

Debe convertir el valor undefined en un valor null para que javascript pueda serializarlo en JSON (convertirlo en JSON).

La forma más fácil de convertir valores undefined en null en javascript es usar una biblioteca llamada Lodash . Instale Lodash usando los siguientes comandos:

 $ npm install lodash // or $ yarn add lodash

Después de eso, cree las siguientes funciones:

 import _ from 'lodash'; function prepareForSerializatoin(obj) { return obj.mapValues(obj, value => typeof value === 'undefined' ? null : value); }

Finalmente, use esta función mientras devuelve su respuesta:

 export async function getServerSideProps(context) { const genre = context.query.genre; const request = await fetch( `https://api.themoviedb.org/3${ requests[genre]?.url || requests.fetchTrending.url }` ).then((res) => res.json()); return prepareForSerializatoin({ props: { results: request.results, }, }); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!