4

i have static app with nextJs 13 without any api data or database in my local machine it work normal ,but in production server with cpanel i have 503 error with this log

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: read EINVAL
    at Pipe.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -22,
  code: 'EINVAL',
  syscall: 'read'
}

I followed the documentation steps and i change scripts start and i add my custom server also

package.json

 "scripts": {
    "dev": "node server.js",
    "build": "next build",
    "start": "NODE_ENV=production node server.js"
  },

server.js

const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const dev = process.env.NODE_ENV !== 'production'
const hostname = 'localhost'
const port = 3000
// when using middleware `hostname` and `port` must be provided below
const app = next({ dev, hostname, port })
const handle = app.getRequestHandler()

app.prepare().then(() => {
  createServer(async (req, res) => {
    try {
      // Be sure to pass `true` as the second argument to `url.parse`.
      // This tells it to parse the query portion of the URL.
      const parsedUrl = parse(req.url, true)
      const { pathname, query } = parsedUrl

      if (pathname === '/a') {
        await app.render(req, res, '/a', query)
      } else if (pathname === '/b') {
        await app.render(req, res, '/b', query)
      } else {
        await handle(req, res, parsedUrl)
      }
    } catch (err) {
      console.error('Error occurred handling', req.url, err)
      res.statusCode = 500
      res.end('internal server error')
    }
  }).listen(port, (err) => {
    if (err) throw err
    console.log(`> Ready on http://${hostname}:${port}`)
  })
})
Boutamente abdessamad
  • 523
  • 2
  • 10
  • 30
  • 1
    I am experiencing the same error since 2 days ago with an unchanged node app on my hoster that uses CloudLinux Cpanel too. Seems a bit much of coincidence that both of us experience that at the same time... Wild speculation: some patch has weird effects? (if this comment is deemed not helpful, please let me know and I will remove it) – TomFree Nov 23 '22 at 10:41
  • MAybe https://stackoverflow.com/questions/74553818/nestjs-app-not-working-on-cpanel-node-selector is insteresting - that the current status of my issue and findings. – TomFree Nov 25 '22 at 17:16
  • @TomFree thanks for your comment, yes , after finish all solutions ,i contact the support and we found that nextjs not working fine with `CloudLinux` and new version of `lightspeed` server , we do a downgrade version and it working fine now – Boutamente abdessamad Dec 26 '22 at 14:09

0 Answers0