fastify / fastify-nextjs

React server side rendering support for Fastify with Next
Other
532 stars 61 forks source link

nextjs plugin trying to get /_next/webpack-hmr and has no current response #720

Open officefish opened 1 year ago

officefish commented 1 year ago

Prerequisites

Fastify version

4.14.1

Plugin version

9.2.0

Node.js version

18.14

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

11.3

Description

Wnen first running application have a problem:

_{"level":30,"time":1680179132786,"pid":13960,"hostname":"techies","reqId":"req-1","res":{"statusCode":404},"responseTime":1114.3266999721527,"msg":"request completed"} [App] error - uncaughtException: Error: write ECONNABORTED [App] at afterWriteDispatched (node:internal/stream_base_commons:160:15) [App] at writeGeneric (node:internal/stream_base_commons:151:3) [App] at Socket._writeGeneric (node:net:930:11) [App] at Socket._write (node:net:942:8) [App] at writeOrBuffer (node:internal/streams/writable:392:12) [App] at _write (node:internal/streams/writable:333:10) [App] at Socket.Writable.write (node:internal/streams/writable:337:10) [App] at ServerResponse._writeRaw (node:_http_outgoing:428:17) [App] at ServerResponse._send (node:_http_outgoing:377:15) [App] at ServerResponse.end (node:_http_outgoing:1019:10) [App] at Gzip.onStreamEnd (D:\practice\fullstack\techies\server\node_modules\next\dist\compiled\compression\index.js:22:1913) [App] at Gzip.emit (node:events:513:28) [App] at Gzip.emit (node:domain:489:12) [App] at endReadableNT (node:internal/streams/readable:1359:12) [App] at processTicksAndRejections (node:internal/process/taskqueues:82:21) { [App] errno: -4079, [App] code: 'ECONNABORTED', [App] syscall: 'write' [App] }

Steps to Reproduce

I tried to fix it with handle request in plugin register, but something seems wrong with this config:

server.register(fastifyNext, { 
        dev: true,
        noServeAssets: true
     })
    .after(() => {
        server.next(`/_next/*`, async (app:NextServer, req:FastifyRequest, reply:FastifyReply) => {

          app.getRequestHandler()(req.raw, reply.raw).then(() => {
            reply.hijack()
          })
        })
})

Expected Behavior

No response

songkeys commented 1 year ago

It looks like a problem on Next.js side https://github.com/vercel/next.js/issues/50461