controller[kState].transformAlgorithm is not a function #75995
Replies: 36 comments 27 replies
|
Hey, Im also experiencing this issue. it's super weird because in other branches of my projects it doesn't show up.
|
|
Yes suuper weird, I understand it has something to do with streaming from Node. |
|
"I'm experiencing the same issue: TypeError: controller[kState].transformAlgorithm is not a function in my Next.js project. Any updates or solutions?" |
|
I had this issue intermittently on my self hosted NextJS 15 app which uses Nginx as a reverse proxy. In my case the issue seems to be around headers / buffers growing to the point where they were getting truncated by Nginx which caused Node to have problems and throw the Kstate error. At the same time could see buffer overrun errors in Nginx "upstream sent too big header whil e reading response header" so I added the following into my server block in the Nginx conf to increase the proxy buffers: After adding this the issue is totally fixed for me (so far!) |
|
We are having the same issue. Really hard to debug |
|
By the way in the unlikely event this helps anyone else - some previously fragile but ok |
|
Posting this here to potentially help others. I was seeing this very frequently and I noticed my app was being scraped relentlessly by AI bots. Seemed to be happening if someone asked ChatGPT or other service and the prompt was terminated prematurely. I'm not entirely sure this is 100% the culprit but haven't seen this error since on my app since updating my robots.txt. |
|
issue seems like gone after next 15.3.0 update, and looks like this error or warning was coming thru react code |
|
In our case we noticed that in one of our middleware checks, for a certain condition we were supposed to perform NextResponse.next({ request: { headers: updatedHeaders } }) and instead we missed out to wrap headers inside request object and passed NextResponse.next({headers: updatedHeaders }) We fixed this and the issue was resolved. |
|
I got the same promblem. My project has been running normally last week. But this week this issue just poped up. it's werid. |
|
same problem |
|
15.3.3 also happening |
|
Interesting, I am getting this locally. I did some debugging. It is inconsistent for me too. It happened a few times. But then stopped. I rebooted the server and it still happened. Tried on incognito too. I have next.js github repo checked out locally I searched for |
|
Same here: It started happening after updating to Next.js 15.5.4 |
|
I encountered the same issue and managed to resolve it with the help of Codex. The solution seems effective. Here's what worked for me: Root CauseThe error occurs due to a conflict between native Web Streams API and Solution
Why this works:
Verification:After the changes, you can verify the polyfill is gone: find node_modules -name "web-streams-polyfill"
# Should return nothingThe ReadableStream → TransformStream pipeline should now work without issues. |
|
Can the NextJS team address this issue? The streaming implementation is useless now. I had to revert my streaming code when it started throwing this error every second and crashing my server on production. The interesting thing is that it happens only on production, and I don't have any option to debug and fix. Now I am scared of upgrading my application to V16. |
|
If i build the project locally and then run I don't get the error |
For those experiencing the issue on EKS.This is not a NextJS team problem. Solution here: Point your health checks to -> /healthcheck Enjoy the silence in the logs ;) |
|
This is the recommended approach to handle the controller[kState].transformAlgorithm error The error TypeError: controller[kState].transformAlgorithm is not a function occurs in specific environments, particularly when running Next.js 15.1.7 with Node 22 in Docker or Kubernetes. It is not consistently reproducible locally and appears to be related to changes in Node internals and Web Crypto API behavior. Steps to address the issue
const algo = controller[kState]?.transformAlgorithm;
Summary This error is environment-specific and related to Node and Next.js internal changes. Using alternative Node versions, checking build modes, and applying defensive coding are the most effective ways to handle it currently. Providing feedback to the Next.js team can help secure a proper fix in upcoming releases. |
|
I have the same issue, and it happens almost once every minute (as reported in Sentry) even if no traffic is on the app. It continues to happens on Node22 and Node23. I don't want to revert to Node18 as it would break other things in my code. I don't know where to start to fix this. All above suggestions seems completely unrelated (img / openai / etc.) The fact that it continues to happen even when there is not traffic is puzzling me. |
|
I have same issue using Parallel route and Intercepting Routes app/[rid]/photo/[id] |
|
For me enabled |
|
We noticed this issue again after quite a while. This time we had not made any changes to images. We are using Code Build + ECS deployments. After a recent deployment the tasks were running fine from around 1am upto 3:50pm, after which we suddenly started seeing the issues - and the tasks kept crashing (and new ones kept getting created with same error logs.) We tried a new build and deployment but the task logs showed errors again - this did not work. In our latest deployment, we had added a package dependency. I deleted the package-lock.json and node_modules folder. Reinstalled packages using npm install command. And then committed the updated package-lock.json. The build and deployment (using this updated package-lock.json) happened successfully, and we are not observing issues again, so far. Just posting here what worked for me, incase it helps someone. |
|
Codex debug results below: Another data point: in our case this was not caused by We reproduced a different variant locally where the immediate failure was a stale Turbopack dev route graph:
The strongest signal was that deleting Workarounds that helped:
So at least in our case, |
|
@J4v4Scr1pt The Root Cause: Stream Controller Mismatch It occurs when a TransformStream (used heavily by Next.js for RSC streaming and SSR) is interacted with after the underlying Node.js stream controller has been partially destroyed or corrupted. In a Kubernetes/Standalone environment, this almost always points to one of three things:
The Fix: Try switching the base image to node:22-bookworm-slim (Debian-based) to rule out musl memory/stream management issues.
When the connection closes prematurely, Next.js tries to finalize the stream. If the controller state is already cleaned up by Node's internal garbage collector, it throws this TypeError. The Fix: Ensure X-Accel-Buffering: no is set in your headers and check if your Ingress has a short proxy timeout.
🛠️ Recommended Action Plan (The "Badge-Winning" Answer) Audit the Stream: Look for any manual usage of new TransformStream() or new ReadableStream() in your API routes or Middleware. Check Ingress Timeouts: If this happens "randomly," it's likely a client-side disconnection or a load balancer timeout occurring while Next.js is still trying to stream React Server Components (RSC) to the browser. Force Global Consistency: Ensure your package.json doesn't have multiple versions of undici via overrides/resolutions. Next.js 15 relies heavily on a specific fetch/stream implementation. Why this is hard to reproduce: |
|
We're still seeing the issue in a standalone production build with NextJS 16.2.3 & Node 24 |
|
Sharing my minimum reproduction + fix in case it helps: https://github.com/Hokid/nextjs-controller-kState-transformAlgorithm-is-not-a-function-repro-and-fix |
|
Looking at @Hokid example I found this PR nodejs/node#62040, so this issue should be fixed from 25.8.1 onwards and backported to version 24.15.0 LTS . This PR should fix this issue so and upgrade to any of these version should get rid of it. I have not tested myself yet but will do soon and report back here ^^ |


Uh oh!
There was an error while loading. Please reload this page.
Summary
I know you want an reproduction on the issue, but this issue is very specific and as it seems not reproduceable locally. Otherwise I would love to provide one!
It seems that more people have this issue and have a hard time tracking down the cause of it. You can read a fairly new thread here. It also seems that this have been there for a while because #68319 thread opened last summer with the same issue. There are more threads about this on StackOverflow etc.
We run an NextJs application (all latest and greatest) in standalone mode in an K8S environment as state above. From time to time this error just shows up. Tried different node versions and going through the code base several times but nothing seems out of order.
I'm unsure how affected our customers are because I don't know when this error fires off, but it's very annoying to see this popping up and a bit scary to not understand if it affects customers.
Help solving this would very much be appreciated.
Additional information
No response
Example
No response
All reactions