Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unhandledRejection: TypeError [ERR_INVALID_ARG_TYPE] #28693

Closed
pgrodrigues opened this issue Sep 1, 2021 · 1 comment · Fixed by #28694
Closed

unhandledRejection: TypeError [ERR_INVALID_ARG_TYPE] #28693

pgrodrigues opened this issue Sep 1, 2021 · 1 comment · Fixed by #28694
Labels
bug Issue was opened via the bug report template.

Comments

@pgrodrigues
Copy link
Contributor

What version of Next.js are you using?

11.1.0

What version of Node.js are you using?

14.17.5

What browser are you using?

Chrome

What operating system are you using?

Windows

How are you deploying your application?

Vercel

Describe the Bug

After upgrading to next 11.1.0, I started getting this error:

error - unhandledRejection: TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received undefined    at Function.byteLength (buffer.js:727:11)
    at ServerResponse.apiRes.end (C:\path-to-project\node_modules\next\dist\server\api-utils.js:73:41)
    at writeend (C:\path-to-project\node_modules\express-session\index.js:262:22)
    at ontouch (C:\path-to-project\node_modules\express-session\index.js:353:11)
    at C:\path-to-project\node_modules\connect-mongo\build\main\lib\MongoStore.js:339:24
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5) {
  code: 'ERR_INVALID_ARG_TYPE'

The code below found in server/api-utils.ts is not accounting for the possibility of the first parameter args[0] being undefined. Since the if condition does not cover such scenario, calling Buffer.byteLength with undefined will result in an error because args[0] type is not a supported type (supported types are: String, Buffer, TypedArray, DataView, ArrayBuffer).

  apiRes.end = (...args: any[2]) => {
    if (args.length && typeof args[0] !== 'function') {
      contentLength += Buffer.byteLength(args[0])
    }

Expected Behavior

No error should happen

To Reproduce

I was able to reproduce this in my app in development that uses:

  • next 11.1.0
  • express-session
  • connect-mongo session store
  • passport
  • next-connect

After logging in and navigating around.

With next 11.0.1, this error does not occur.

@pgrodrigues pgrodrigues added the bug Issue was opened via the bug report template. label Sep 1, 2021
@kodiakhq kodiakhq bot closed this as completed in #28694 Sep 1, 2021
kodiakhq bot pushed a commit that referenced this issue Sep 1, 2021
## Bug
Fixes #28693

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants