Skip to content

uncaughtException: TypeError: res.once is not a function #33726

Closed
getsentry/sentry-javascript
#4467
@yodakaEngineer

Description

@yodakaEngineer

Run next info (available from version 12.0.8 and up)

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101
Binaries:
  Node: 16.13.2
  npm: 8.1.2
  Yarn: 1.22.17
  pnpm: N/A
Relevant packages:
  next: 12.0.9
  react: 17.0.2
  react-dom: 17.0.2

What version of Next.js are you using?

12.0.9

What version of Node.js are you using?

16.13.2

What browser are you using?

Chrome

What operating system are you using?

macOS(Apple Silicon)

How are you deploying your application?

next start, but this is occurred local.

Describe the Bug

I use custom server only local to use https.
I upgraded Next.js from 11.1.2 to 12.0.9.
Then, when I reload once, browser no longer finishes loading.
And I got this error.

error - uncaughtException: TypeError: res.once is not a function

Expected Behavior

To finish reloading with no error.

To Reproduce

  1. Set server.js, ./certificates/default.key and ./certificates/default.crt
  2. Change package.json
  "scripts": {
    "dev": "node ./server.js",
    ...
  },
  1. yarn dev
  2. Load browser at the first time is success( but error has appeared )
  3. Reload browser
  4. never ending reload with error

This is my server.js.

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

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

const httpsOptions = {
    key: fs.readFileSync('./certificates/default.key'),
    cert: fs.readFileSync('./certificates/default.crt')
}

app.prepare().then(() => {
    createServer(httpsOptions, (req, res) => {
        const parsedUrl = parse(req.url, true)
        handle(req, res, parsedUrl)

    }).listen(3000, err => {
        if (err) throw err
    })
})

Additional Context

it works on Next.js 11.1.2.
So, ./certificates/default.key and ./certificates/default.crt are no problem.
I need to use https at local because I develop PWA with next-pwa 5.4.4.

I think probably RequestHandler become not to be able to handle res of argument of callback function of createServer of https on Next.js 12?
Or this may be related https://nextjs.org/docs/upgrading#nextjs-hmr-connection-now-uses-a-websocket.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions