next.js: TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed
Link to the code that reproduces this issue
https://github.com/willianrod/next-readable-stream-error
To Reproduce
- Run the project locally
- Go to
/auth/login - The app will redirect you to
/sample/listafter resolving the promise - You should now see the error on your console
Current vs. Expected behavior
Current: Right now, when I’m navigating between pages with server components I’m seeing errors on my development console. Expected: When navigating between pages no errors should be prompted
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:23 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6020
Binaries:
Node: 18.16.0
npm: 9.5.1
Yarn: 1.22.19
pnpm: 8.6.12
Relevant Packages:
next: 13.5.1
eslint-config-next: 13.5.1
react: 18.2.0
react-dom: 18.2.0
typescript: 5.2.2
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
App Router
Additional context
There is a discussion with more people with the same issue. The latest request was to update to the latest version 13.5.1 and see if the issue was still happening.
https://github.com/vercel/next.js/discussions/55027
Internal error: TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed
at new NodeError (node:internal/errors:399:5)
at ReadableByteStreamController.enqueue (node:internal/webstreams/readablestream:1150:13)
at /path/to/app/readable-error/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:1:447268
at ut (/path/to/app/readable-error/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:1:447318)
at ct (/path/to/app/readable-error/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:1:446596)
at Timeout._onTimeout (/path/to/app/readable-error/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:1:443766)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Reactions: 18
- Comments: 28 (8 by maintainers)
Should be fixed by #56012 which carried the react change
Looks like a form of this error started to happen after:
Could someone else double check by using next@13.4.13-canary.3, verify no error, and then use next@13.4.13-canary.4, to see the error?
I tried updating next and node to the latest versions, but the error was still present. It seems to be related to how caching is handled. Changing caching to dynamic worked for me.
export const dynamic = 'force-dynamic'I get the same issue as well. When I run Playwright tests it happens in the same place the old error was happening.
upgraded to 13.5.4-canary.2
still I get
Has anyone noticed any actual negative effects from this? I’m working on two separate apps more or less simultaneously, and they’re both experiencing this same error but both are performing as they should as far as I can tell, but it is a bit concerning…
This should be fixed by https://github.com/facebook/react/pull/27405
Same problem here i don’t use suspense in my layout but i use loading.tsx file this error doesn’t cause any problem in my build (i update next to 13.5.1 but it’s not fixing anything!)
@icyJoseph yep, I can confirm that the error started after
next@13.4.13-canary.4.If I would guess, the error is originated on pipeReadable
Diff between
next@13.4.13-canary.3andnext@13.4.13-canary.4https://github.com/vercel/next.js/compare/v13.4.13-canary.3...v13.4.13-canary.4#diff-9be48534a043c68023eef0f61dacd526b677c70ee3b61807b9da74a279aba2e5R41