question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError on production server (ERR_INVALID_ARG_TYPE)

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
camjwcommented, 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!

1reaction
williamsteincommented, Nov 18, 2021

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 😃.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument ...
It says, that this error occurs when the react-scripts version is old. So, delete all your current node modules, install the latest react- ......
Read more >
ERR_INVALID_ARG_TYPE · Issue #22630 · nodejs/node
Run CLI with --verbose flag for more details. TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
Read more >
[Fix] TypeError [ERR_INVALID_ARG_TYPE]: The “path ...
[Fix] TypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be of type ... In this story I'll go over three fixes you can try to...
Read more >
typeerror [err_invalid_arg_type]: the "string" argument must be ...
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object.
Read more >
Errors | Node.js v19.3.0 Documentation
Class: TypeError #. Extends <errors.Error>. Indicates that a provided argument is not an allowable type. For example, passing a function to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found