Custom server renderToHTML does not work with next 13.5.1
Unanswered
Korat posted this in #help-forum
KoratOP
Link to the code that reproduces this issue or a replay of the bug
https://github.com/thilohaas/nextjs-custom-server/tree/main
https://codesandbox.io/p/github/thilohaas/nextjs-custom-server/main
To Reproduce
1. Start a new nextjs project with npx create-next-app@latest
2. Add a server.js https://github.com/thilohaas/nextjs-custom-server/blob/main/server.js
3. Change the package.json dev script to:
4. run
5. open http://localhost:3001
Current vs. Expected behavior
I expect it to display the welcome page but instead i get an error from the next server:
For me this problem is also related to this one: https://github.com/vercel/next.js/issues/53466
Obstacles have appeared in large projects with their own infrastructure (Kube).
These problems are associated with the use of Custom-Server, which is a great need for additional collection of metrics, custom logging, control of response headers and status, etc. I also need the ability to run in one thread so that the AsyncLocalStorage context is saved and other global mechanics work.
On versions higher than 13.4.12 (I confirm, the problem appears with 13.4.13-canary.0) it became impossible to create a custom-server. Now when calling methods, and even render, I get errors when calling server methods: Invariant ... called outside render worker.
The Next server is initializing, but it seems to be isolated from my Fastify server, or the new code is broken.
It seems to me that vercel-team added these changes that affected an important part of the community.
https://github.com/thilohaas/nextjs-custom-server/tree/main
https://codesandbox.io/p/github/thilohaas/nextjs-custom-server/main
To Reproduce
1. Start a new nextjs project with npx create-next-app@latest
2. Add a server.js https://github.com/thilohaas/nextjs-custom-server/blob/main/server.js
3. Change the package.json dev script to:
"dev": "node server.js",4. run
npm run dev5. open http://localhost:3001
Current vs. Expected behavior
I expect it to display the welcome page but instead i get an error from the next server:
Error: Invariant ensurePage called outside render workerFor me this problem is also related to this one: https://github.com/vercel/next.js/issues/53466
Obstacles have appeared in large projects with their own infrastructure (Kube).
These problems are associated with the use of Custom-Server, which is a great need for additional collection of metrics, custom logging, control of response headers and status, etc. I also need the ability to run in one thread so that the AsyncLocalStorage context is saved and other global mechanics work.
On versions higher than 13.4.12 (I confirm, the problem appears with 13.4.13-canary.0) it became impossible to create a custom-server. Now when calling methods, and even render, I get errors when calling server methods: Invariant ... called outside render worker.
The Next server is initializing, but it seems to be isolated from my Fastify server, or the new code is broken.
It seems to me that vercel-team added these changes that affected an important part of the community.
1 Reply
Ratonero Valenciano
Any can help?