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

Error: invariant: dynamic responses cannot be unchunked #45509

Closed
1 task done
todorpopov93 opened this issue Feb 2, 2023 · 18 comments
Closed
1 task done

Error: invariant: dynamic responses cannot be unchunked #45509

todorpopov93 opened this issue Feb 2, 2023 · 18 comments
Labels
bug Issue was opened via the bug report template. locked please add a complete reproduction The issue lacks information for further investigation

Comments

@todorpopov93
Copy link

todorpopov93 commented Feb 2, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

A next 13 production build hosted on GCP Kubernetes

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue

it's a private repository and I cannot share the code. I think it should be easily reproducible

To Reproduce

Just run the latest Nextjs 13 on production

Describe the Bug

Hello,

I have recently installed the latest next 13 ("next": "13.1.4"), and ran it on production (despite being experimental yet) and started receiving occasional error logs on the server side. However, the web app itself loads properly and everything works normally so far (2 days up time on production).

Here is the error:

Error: invariant: dynamic responses cannot be unchunked. This is a bug in Next.js at RenderResult.toUnchunkedString (/usr/src/app/node_modules/next/dist/server/render-result.js:16:19) at /usr/src/app/node_modules/next/dist/server/response-cache/index.js:103:57 at processTicksAndRejections (node:internal/process/task_queues:96:5)

Expected Behavior

Not to have this bug log in Next 13 I suppose

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@todorpopov93 todorpopov93 added the bug Issue was opened via the bug report template. label Feb 2, 2023
@itsuki0927
Copy link

+1

@Arctomachine
Copy link

Encountered this issue at 13.0.6. Other than getting it seemingly randomly, one situation where it was triggered is running online schema validator

@timneutkens timneutkens added the please add a complete reproduction The issue lacks information for further investigation label Feb 27, 2023
@github-actions
Copy link
Contributor

We cannot recreate the issue with the provided information. Please add a reproduction in order for us to be able to investigate.

Why was this issue marked with the please add a complete reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository (template), but you can also use a tool like CodeSandbox or StackBlitz.

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue.

Please test your reproduction against the latest version of Next.js (next@canary) to make sure your issue has not already been fixed.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

What happens if I don't provide a sufficient minimal reproduction?

Issues with the please add a complete reproduction label that receives no meaningful activity (e.g. new comments with a reproduction link) are automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the 👍 reaction on the topmost comment (please do not comment "I have the same issue" without reproduction steps). Then, we can sort issues by votes to prioritize.

I think my reproduction is good enough, why aren't you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

@Clarity-89
Copy link

Clarity-89 commented Mar 7, 2023

Happened to me as well, with app directory enabled. Seems like it was caused by another error, in this case I was desctructuring const post = allPosts.find((p) => p.id === id), where post was occasionally undefined. Fixing that error also removed the dynamic responses cannot be unchunked error, so I'd suggest to check if you have any other errors in your app that may cause this.

Edit: Nevermind, seems like error still appears randomly on production. Started happening after upgrading to Next.js 13.2.3 and switching to app directory.

@thevuong
Copy link

thevuong commented Mar 13, 2023

Screen.Recording.2023-03-13.at.10.32.23.PM.mov

I also get the same error when I upgrade to version 13.2.4, in version 13.2.3 I don't get that error.

I confirm that the error occurs when the User-Agent is a bot like Google Bot Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/110.0.5481.177 Safari/537.36 and the page must have not been visited before.

@Arctomachine
Copy link

Since you figured out how it is triggered, did you perhaps find severity of this bug? Does it make something work worse or does it just leave error in log without breaking anything (requesting bot included)?

@todorpopov93
Copy link
Author

Happened to me as well, with app directory enabled. Seems like it was caused by another error, in this case I was desctructuring const post = allPosts.find((p) => p.id === id), where post was occasionally undefined. Fixing that error also removed the dynamic responses cannot be unchunked error, so I'd suggest to check if you have any other errors in your app that may cause this.

Edit: Nevermind, seems like error still appears randomly on production. Started happening after upgrading to Next.js 13.2.3 and switching to app directory.

the problem is that for me it's happening since 13.1.4, but that was the first version that I did try and also ran on prodution, so it might be occurring from even earlier versions. And the worst is that I cannot give any steps to reproduce it, as I haven't done anything special.. having 1 page, 1 fetch and react components loaded is something that I don't think has anything special on it..
I think the issue lies somewhere within nextjs package itself, but it's not specific/not detailed and can't understand how to have it fixed (if possible at all).

@todorpopov93
Copy link
Author

I also get the same error when I upgrade to version 13.2.4, in version 13.2.3 I don't get that error.

I would try this out with increasing my version to 13.2.3 and will leave feedback here if it worked for me. Thank you!

@davidbnk
Copy link

I'm experiencing this in production as well, next v13.2.4
Have no clue how to reproduce it because I never saw it during dev and there is no useful information in the error message

@Arctomachine
Copy link

Still happens in 13.3. This error makes up most of production logs, being outputed regularly.
Is there relation to hosting type? In my case server is self hosted on vps.

@PassTheMayo
Copy link

This error is still happening on NextJS 13.4.1. I'm currently using the app directory without Turbo if that helps at all.

image

@somersby10ml
Copy link

next 13.4.1 AppRouter is in use and

yarn build->yarn start `

After a few hours or days, you will see an error and the
server is not working.

Error: invariant: dynamic responses cannot be unchunked. This is a bug in Next.js
node_modules\next\dist\server\response-cache\index.js:119:57
node_modules\next\dist\server\render-result.js:28:19

@nithin-murali-arch
Copy link

I was using a custom server implementation, where I use app.renderToHTML. This causes the issue for me.

@cloetensbrecht
Copy link

We're getting the same issue in v 13.4.4 with AppRouter.
The website works fine, but the error log is full of these types of errors.
The server is a Windows server running PM2.

Error: invariant: dynamic responses cannot be unchunked. This is a bug in Next.js
	at RenderResult.toUnchunkedString (C:\wwwNodeJs\*****\node_modules\next\dist\server\render-result.js:28:19)
	at C:\wwwNodeJs\*****\node_modules\next\dist\server\response-cache\index.js:119:57

In node_modules\next\dist\server\render-result.js:

toUnchunkedString() {
	if (typeof this._result !== "string") {
		throw new Error("invariant: dynamic responses cannot be unchunked. This is a bug in Next.js");
	}
	return this._result;
}

'invariant: dynamic responses cannot be unchunked. This is a bug in Next.js'

@AGalbe
Copy link

AGalbe commented Jun 23, 2023

We're getting the same issue in v 13.4.4 with AppRouter. The website works fine, but the error log is full of these types of errors. The server is a Windows server running PM2.

Error: invariant: dynamic responses cannot be unchunked. This is a bug in Next.js
	at RenderResult.toUnchunkedString (C:\wwwNodeJs\*****\node_modules\next\dist\server\render-result.js:28:19)
	at C:\wwwNodeJs\*****\node_modules\next\dist\server\response-cache\index.js:119:57

In node_modules\next\dist\server\render-result.js:

toUnchunkedString() {
	if (typeof this._result !== "string") {
		throw new Error("invariant: dynamic responses cannot be unchunked. This is a bug in Next.js");
	}
	return this._result;
}

'invariant: dynamic responses cannot be unchunked. This is a bug in Next.js'

I'm getting the same error v 13.4.4. Did you solve it? Thanks!

@charnog
Copy link

charnog commented Jul 13, 2023

Was resolved in #52581

@balazsorban44
Copy link
Member

Closing as per the above comment. Feel free to reopen with a new reproduction if you are still seeing this!

Copy link
Contributor

github-actions bot commented Nov 4, 2023

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Nov 4, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2023
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. locked please add a complete reproduction The issue lacks information for further investigation
Projects
None yet
Development

No branches or pull requests