TypeError on production server (ERR_INVALID_ARG_TYPE)
See original GitHub issueWhat 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)
- Build:
yarn install && yarn build
- Zip build before uploading:
mkdir dist && zip dist/***.zip -r dist .next package.json yarn.lock next.config.js public
- From the generated zip,
npm install && npm run start
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 agetServerSideProps
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!
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:
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 😃.