Closed thilohaas closed 1 month ago
I'm seeing this error as well, when using next-dev-https
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. @ijjk It seems to me that you added these changes that affected an important part of the community.
We are having the same issue with a custom Express server
We are facing the same issue when using renderToHTML with a custom http server, is there a temporary work around?
@salman-mazhar We are waiting for @ijjk.
@jiebaibai please use English to report your issue, so others can understand, thanks
@jiebaibai please use English to report your issue, so others can understand, thanks
@ijjk 13.5.5 also has this problem, after customizing server.js, app.renderToHTML exception,catch error is: TypeError: Cannot read properties of undefined (reading 'ensurePage')
Also face a similar issue in Custom Server. Our AssetPrefix is partially working.
Same issue with Next 14.0.3 with custom server. We are having a hapi server
Same problem here with custom server + renderToHTML + hydrate components :disappointed: any temporary solution?
We are facing the same issue when using renderToHTML with a custom http server, anyone can help me ?
Any update for this issue ? we are facing the same issue with hapi js. renderToHTML issue , version 13.4
The isRenderWorker is always undefined in next-dev-server. So it will work if we turn off the development mode, build the dist folder and run it without next server.
Same issue with Next 14.0.4 with custom server.
do not use custom next serve. manage routers via next.config.js
I have a same problem with next 14.1.0 with custom server. Any update for this issue ?
Also seeing this error
I solved my problem by managing the routes in next.config.js
@duzgunemreozkan yeah, you mentioned.
Maybe you might elaborate on how you are able to replicate the functionality of Express in the next.config.js, that would be helpful
Same error here (Next 14. while trying to work with Hydrate and Stencil (Web Components).
TypeError: Cannot read properties of undefined (reading 'ensurePage')
Looking through the code, seems like it *might" only be an issue with the dev server. Might be worth seeing if it will run in production mode
On Fri, 16 Feb 2024, 14:03 Azrael Garden, @.***> wrote:
Same error here (Next 14. while trying to work with Hydrate and Stencil (Web Components). TypeError: Cannot read properties of undefined (reading 'ensurePage')
— Reply to this email directly, view it on GitHub https://github.com/vercel/next.js/issues/54977#issuecomment-1948441665, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABQAYKWTU3GIBD7U55TDBDYT5RKPAVCNFSM6AAAAAA4KOUVACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBYGQ2DCNRWGU . You are receiving this because you commented.Message ID: <vercel/next. @.***>
Iam facing the same issue. Iam not able to use renderToHTML on custom server. Iam using next 13.4. Any workaround for this issue. I also tried on the latest version but it still not worked.
I'm seeing the same error with custom server (I'm using Hapi)
Any update or workaround on this ? We are planning to upgrade to next 14.2.3 from 12 and see this issue.
We ran into this problem too, it's with renderToHtml only in dev mode. We got around it by calling app.render in dev mode instead.
We ran into this problem too, it's with renderToHtml only in dev mode. We got around it by calling app.render in dev mode instead.
This worked for my team also, going from 13.2.3
to 14.2.4
Nvm saw errors in server
A workaround is to directly access the internal Dev/Node server inside the app object.
const appHtml = await (app as any).renderServer.server.renderToHTML(req, res, pathname!, query);
This works with 14.2.4
.
Problem is the getServer()
method. Which is called on the app ( CustomServer
) object, but not on the already created DevNextServer
. Therefor another new server is created with an undefined bundlerService
. app
(which is a CustomServer), has no serverPromise
.
app.renderServer or app.renderServer.server are the correct objects.
Aslo face the same thing,when use customServer to get the page html to cache in redis。
const html = await app.renderToHTML(req, res, pathname, query);
Alway error: Invariant: dynamic responses cannot be unchunked. This is a bug in Next.js
Nextjs version: 14.2.3
Hey, I'm also facing the same issue, are there any updates for this? I'm using Next.js version 14.2.4.
Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!
Fixed by using render
instead of renderToHtml
Fixed by using
render
instead ofrenderToHtml
render directly sends the payload to the response. If you want to work with the html generated, this is not an option.
Hi, the renderToHtml
API is not a public API/not documented nor used in any examples. So the response here https://github.com/vercel/next.js/issues/54977#issuecomment-2354102135 saying to use the proper public API render
is correct.
If you want to work with the html generated, this is not an option
This is not supported with streaming as otherwise you are buffering the response to capture the HTML if you wanna do transforms on the stream which is highly risky that would be a use case for middleware or similar.
I'm gonna close this as it doesn't seem to be a valid/supported use case.
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.
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
npx create-next-app@latest
const dev = process.env.NODE_ENV !== "production"; const hostname = 'localhost'; const port = process.env.PORT || 3001; // when using middleware
hostname
andport
must be provided below const app = next({ hostname, port, dev }); const handle = app.getRequestHandler();app.prepare().then(() => { createServer(async (req, res) => { try { const parsedUrl = parse(req.url, true); const { pathname, query } = parsedUrl;
}).listen(port, (err) => { if (err) throw err; console.log(
> Ready on http://${hostname}:${port}
); }); });Error: Invariant ensurePage called outside render worker
Which area(s) are affected? (Select all that apply)
Not sure
Additional context
No response