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

SSR caching example is broken (UnhandledPromiseRejectionWarning: TypeError: argument entity is required) #16725

Closed
omar-dulaimi opened this issue Aug 31, 2020 · 10 comments · Fixed by #18786
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@omar-dulaimi
Copy link

Bug report

Describe the bug

The SSR caching login is broken with the error below.

(node:14465) UnhandledPromiseRejectionWarning: TypeError: argument entity is required
    at etag (/home/omar/Desktop/ssr-caching-app/node_modules/etag/index.js:72:11)
    at /home/omar/Desktop/ssr-caching-app/node_modules/cacheable-response/index.js:95:32
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:14465) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:14465) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to https://github.com/vercel/next.js/tree/canary/examples/ssr-caching
  2. Run locally
  3. Access the website
  4. See error in the terminal (notice the speed and the missing headers in the response)

Expected behavior

It should cache pages normally.

System information

  • OS: Ubuntu 18.04
  • Browser (if applies): Chrome
  • Version of Next.js: 9.5.2(latest)
  • Version of Node.js: 12.16.2

Additional context

It was working fine on our project, until it didn't when I upgraded to v9.5.2 from v9.5.1
So I thought of testing the official example, just to find out the same issue!

@ppbl
Copy link

ppbl commented Sep 2, 2020

9.5.1 is not working for me 😂
a new user of next wants to configure ssr-caching and is very frustrated

@omar-dulaimi
Copy link
Author

Any update on this?

@mikhalev-im
Copy link

mikhalev-im commented Sep 7, 2020

It is related to:

Not sure what is the plan here, is it safe to still use renderToHTML or is it gonna be made private soon

@omar-dulaimi
Copy link
Author

omar-dulaimi commented Sep 8, 2020

This is so sudden, they've already broken our production application. There should be a quick alternative.

@ppbl
Copy link

ppbl commented Sep 9, 2020

#14737 (comment)

Refer to @Charioteer‘s ideas

Modify the get method of ssr-caching demo

get: async ({ req, res }) => {
      const rawResEnd = res.end
      const data = await new Promise((resolve) => {
          res.end = (payload) => {
              if (res.statusCode === 200) {
                  resolve(payload)
              } else {
                  resolve()
              }
          }
          app.render(req, res, req.path, {
              ...req.query,
              ...req.params,
          })
      })
      res.end = rawResEnd
      return { data }
},     

Currently we can write like this first 😊

Since the response needs to be terminated correctly when the send is executed, the res.end modified in get needs to be restored

@ivanpetrushev
Copy link

I have the same error in Next.js rendering with serverless target. I can't see how exactly is this connected to our app code from this stack trace. Is this a problem with the vendor etag package?

Versions are:
Next.js 9.5.3
[email protected]

TypeError: argument entity is required,
            at etag (/var/task/node_modules/next/dist/compiled/etag/index.js:1:738),
            at sendPayload (/var/task/node_modules/next/dist/next-server/server/send-payload.js:1:473),
            at renderReqToHTML (/var/task/pages/_error.js:732:13),
            at processTicksAndRejections (internal/process/task_queues.js:97:5),
            at async Module.render (/var/task/pages/_error.js:801:22),
            at async handleOriginRequest (/var/task/index.js:5531:9),
            at async Runtime.handler$1 [as handler] (/var/task/index.js:5398:20)

@jhvissotto
Copy link

I have the same problem.

@omar-dulaimi
Copy link
Author

@ppbl Even with that workaround, the issue still occurs.
Perhaps it's time for Nextjs team to take action.

@erict-dev
Copy link

We rely on renderToHtml in order to modify the raw html server side before sending it to the client, it seems like that’s on shaky ground. Can we get an alternate solution for rendering out raw HTML using nextjs?

@fabioespinosa
Copy link
Contributor

@leerob seems like example is still broken:

/var/task/next.js/examples/ssr-caching/node_modules/etag/index.js:72
    throw new TypeError('argument entity is required')
          ^

TypeError: argument entity is required
    at etag (/var/task/next.js/examples/ssr-caching/node_modules/etag/index.js:72:11)

@vercel vercel deleted a comment from omar-dulaimi Sep 5, 2021
@vercel vercel locked as resolved and limited conversation to collaborators Sep 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants