Comparte:
Error en: const data = await res.json()
Curso: Desarrollo Full-Stack con Laravel, Next.js y Digital Ocean
Siguiendo el Video 2: Desarrollo de un cliente con Next.js
NOTA: He realizado pruebas con diferentes versiones de node ( 14, 16, 18 y 19 ) obteniendo mismos errores
Al ejecutar el: const data = await res.json() me envía el siguiente error:
Siguiendo el Video 2: Desarrollo de un cliente con Next.js
NOTA: He realizado pruebas con diferentes versiones de node ( 14, 16, 18 y 19 ) obteniendo mismos errores
Al ejecutar el: const data = await res.json() me envía el siguiente error:
Server Error
TypeError: terminated
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Este es mi código:
import Link from 'next/link';
export async function getStaticProps() {
console.log('Iniciamos')
const res = await fetch ('http://127.0.0.1:8000/api/books')
console.log('sali del fetch')
console.log(res)
console.log('----')
const data = await res.json()
return {
props: {
books: data
}
}
}
Los mensajes en la consola del servidor son:
Iniciamos
sali del fetch
Response {
[Symbol(realm)]: null,
[Symbol(state)]: {
aborted: false,
rangeRequested: false,
timingAllowPassed: true,
requestIncludesCredentials: true,
type: 'default',
status: 200,
timingInfo: {
startTime: 326072.3169000149,
redirectStartTime: 0,
redirectEndTime: 0,
postRedirectStartTime: 326072.3169000149,
finalServiceWorkerStartTime: 0,
finalNetworkResponseStartTime: 0,
finalNetworkRequestStartTime: 0,
endTime: 0,
encodedBodySize: 349,
decodedBodySize: 349,
finalConnectionTimingInfo: null
},
cacheState: '',
statusText: 'OK',
headersList: HeadersList {
[Symbol(headers map)]: [Map],
[Symbol(headers map sorted)]: null
},
urlList: [ [URL] ],
body: { stream: undefined }
},
[Symbol(headers)]: HeadersList {
[Symbol(headers map)]: Map(9) {
'host' => '127.0.0.1:8000',
'date' => 'Fri, 23 Dec 2022 20:34:57 GMT, Fri, 23 Dec 2022 20:34:57 GMT',
'connection' => 'close',
'x-powered-by' => 'PHP/8.1.6',
'cache-control' => 'no-cache, private',
'content-type' => 'application/json',
'x-ratelimit-limit' => '60',
'x-ratelimit-remaining' => '59',
'access-control-allow-origin' => '*'
},
[Symbol(headers map sorted)]: null
}
}
----
error - TypeError: terminated
at Fetch.onAborted (node:internal/deps/undici/undici:11000:53)
at Fetch.emit (node:events:513:28)
at Fetch.terminate (node:internal/deps/undici/undici:10272:14)
at Object.onError (node:internal/deps/undici/undici:11095:36)
at Request.onError (node:internal/deps/undici/undici:6477:31)
at errorRequest (node:internal/deps/undici/undici:8440:17)
at Socket.onSocketClose (node:internal/deps/undici/undici:7895:9)
at Socket.emit (node:events:513:28)
at TCP.<anonymous> (node:net:313:12) {
page: '/libros',
[cause]: SocketError: closed
at Socket.onSocketClose (node:internal/deps/undici/undici:7883:35)
at Socket.emit (node:events:513:28)
at TCP.<anonymous> (node:net:313:12) {
code: 'UND_ERR_SOCKET',
socket: {
localAddress: undefined,
localPort: undefined,
remoteAddress: undefined,
remotePort: undefined,
remoteFamily: undefined,
timeout: undefined,
bytesWritten: 180,
bytesRead: 656
}
}
}
error - TypeError: terminated
at Fetch.onAborted (node:internal/deps/undici/undici:11000:53)
at Fetch.emit (node:events:513:28)
at Fetch.terminate (node:internal/deps/undici/undici:10272:14)
at Object.onError (node:internal/deps/undici/undici:11095:36)
at Request.onError (node:internal/deps/undici/undici:6477:31)
at errorRequest (node:internal/deps/undici/undici:8440:17)
at Socket.onSocketClose (node:internal/deps/undici/undici:7895:9)
at Socket.emit (node:events:513:28)
at TCP.<anonymous> (node:net:313:12) {
page: '/libros',
[cause]: SocketError: closed
at Socket.onSocketClose (node:internal/deps/undici/undici:7883:35)
at Socket.emit (node:events:513:28)
at TCP.<anonymous> (node:net:313:12) {
code: 'UND_ERR_SOCKET',
socket: {
localAddress: undefined,
localPort: undefined,
remoteAddress: undefined,
remotePort: undefined,
remoteFamily: undefined,
timeout: undefined,
bytesWritten: 180,
bytesRead: 656
}
}
}
Jorge García (2908 xp)
Hola José, tienes encendido el servidor de Laravel? Next.js lo necesita para generar las vistas