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

TypeError on production server (ERR_INVALID_ARG_TYPE) #31471

Closed
futurepastori opened this issue Nov 16, 2021 · 11 comments
Closed

TypeError on production server (ERR_INVALID_ARG_TYPE) #31471

futurepastori opened this issue Nov 16, 2021 · 11 comments
Labels
bug Issue was opened via the bug report template.

Comments

@futurepastori
Copy link

futurepastori commented Nov 16, 2021

What version of Next.js are you using?

12.0.4

What version of Node.js are you using?

14.17.6

What browser are you using?

Chrome (it doesn't matter)

What operating system are you using?

macOS

How are you deploying your application?

elastic beanstalk

Describe the Bug

Running next start after a successful build, the following error happens. Only happens on server-side rendered pages, as client-side rendered pages and navigation work as usual.

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received undefined
    at Writable.write (internal/streams/writable.js:285:13)
    at /Users/victor/Downloads/app-b64f-211115_222948-stage-211115_222948/node_modules/next/dist/server/render.js:1123:37
    at Array.forEach (<anonymous>)
    at /Users/victor/Downloads/app-b64f-211115_222948-stage-211115_222948/node_modules/next/dist/server/render.js:1123:16
    at /Users/victor/Downloads/app-b64f-211115_222948-stage-211115_222948/node_modules/next/dist/server/render.js:1110:13
    at /Users/victor/Downloads/app-b64f-211115_222948-stage-211115_222948/node_modules/next/dist/server/render.js:1110:47
    at /Users/victor/Downloads/app-b64f-211115_222948-stage-211115_222948/node_modules/next/dist/server/render.js:1128:9
    at /Users/victor/Downloads/app-b64f-211115_222948-stage-211115_222948/node_modules/next/dist/server/render.js:1110:13
    at /Users/victor/Downloads/app-b64f-211115_222948-stage-211115_222948/node_modules/next/dist/server/render.js:1110:47
    at /Users/victor/Downloads/app-b64f-211115_222948-stage-211115_222948/node_modules/next/dist/server/render.js:1128:9 {
  code: 'ERR_INVALID_ARG_TYPE'
}

First time after upgrading Next.js to 12.0.4.

Expected Behavior

Server-side rendering to work.

To Reproduce

Happened only after deployed to an EB environment and could reproduce locally from the exact artifacts generated on deploy time (so I'm afraid I may be the one to blame)

  1. Build: yarn install && yarn build
  2. Zip build before uploading: mkdir dist && zip dist/***.zip -r dist .next package.json yarn.lock next.config.js public
  3. From the generated zip, npm install && npm run start
@futurepastori futurepastori added the bug Issue was opened via the bug report template. label Nov 16, 2021
@jackyef
Copy link
Contributor

jackyef commented Nov 16, 2021

I am facing a similar error, though for me it happens even in development. #31478

Curious, do you have a custom _document in your next app? If you do, how does it look?

@futurepastori
Copy link
Author

futurepastori commented Nov 16, 2021

@camjw
Copy link

camjw commented Nov 16, 2021

I also am getting this error on pages that have getServerSideProps methods. Specifically, we have an auth flow where we redirect / to /auth/sign_in which then has a getServerSideProps method. When we redirect from / to /auth/sign_in it works fine, but when I refresh the page on that route it then gives this error. The same thing happens on a couple of other routes.

It only fails when running on elastic beanstalk, when I build the app and run it locally it works fine.

The _document only adds random meta tags, there's no custom methods.

We're using next v12.0.0.

Hope this is useful!

@camjw
Copy link

camjw commented Nov 16, 2021

Downgrading from next v12.0.0 to next v11.1.2 fixed this! There are quite a few google hits for this error and elastic beanstalk in a variety of contexts so I imagine it's really due to some quirk there.

@darwinshameran
Copy link

darwinshameran commented Nov 16, 2021

Having the same issue making a request to a serverless function on Vercel. We're running next v12.0.4.

@mztnnrt
Copy link

mztnnrt commented Nov 18, 2021

I also had same error, my error situation is in docker container.
now, change nextjs version (yarn add next@^11.1.2) from 12.0.3, the error is disappear.

@williamstein
Copy link

Summary: I built with 12.0.3 and served with 12.0.4, and that caused this problem for me. Upgrading my build environment to 12.0.4 fixes the issue. Details below.

I have the exact same issue when attempting to use a production build. I'm not using a custom _document, but my pages all have a custom getServerSideProps method.

I built everything using next 12.0.3, but I'm running the build artifacts using next 12.0.4, because of semver and my build pipeline. This is totally broken.

Exactly the same code built and worked fine with next 12.0.3 both for building and for serving my nextjs site. Thus I can try two things:

  • upgrade my build to use 12.0.4: I tried this and it does work.
  • downgrade my production site to use 12.0.3. This would of course work, since that's exactly what I was doing last week.

It seems like there is a serious semver mistake in tagging 12.0.4 via semver as being compatible with 12.0.3. Technically, I guess it should be 13.0.0 :-).

@Webbanditten
Copy link

We have the same issue with our build where 12.0.4 and up is breaking our build. It seems like it will get patched in 12.0.8.

@balazsorban44
Copy link
Member

PR #32247 might be related, which is part of 12.0.8-canary.3 and higher.

@futurepastori could you give yarn add next@canary a try?

@futurepastori
Copy link
Author

@balazsorban44 might be! Tried and can't reproduce the error anymore, even after running prod server on versions lower than build target.

Closing, thanks!

@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

No branches or pull requests

8 participants