question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
ppblcommented, Sep 9, 2020

https://github.com/vercel/next.js/issues/14737#issuecomment-680092517

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

9reactions
fabioespinosacommented, May 23, 2021

@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)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js SSR Caching using custom server - Stack Overflow
(node:20872) UnhandledPromiseRejectionWarning: TypeError: argument entity is required at etag (C:\xampp\htdocs\next-app\node_modules\etag\index.
Read more >
Next.js Ssr Caching Example - StackBlitz
Run official live example code for Next.js Ssr Caching, created by Vercel on StackBlitz.
Read more >
typeerror [err_invalid_arg_type]: the "id" argument must be of type ...
Before continuing with the command, ensure that the required argument is present. If not, return an error message. For example.
Read more >
CS3281 - Knowledge gained from Projects - GitHub Pages
For example, if we want to get API data of the authenticated user from ... Since arguments are space-separated, this essentially breaks the ......
Read more >
Query: Advanced Search - Wikimedia Phabricator
T147614 Vagrant provision breaks with "Error: your composer.lock file is not up to ... T271758 Support and require BCP 47 tags in <langconvert>...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found