vercel / next.js

The React Framework
https://nextjs.org
MIT License
126.92k stars 26.98k forks source link

`res.revalidate()` only working on Vercel deployment #47017

Open jfbaraky opened 1 year ago

jfbaraky commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:37 PDT 2022; root:xnu-8020.121.3~4/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.14.0
      npm: 9.3.1
      Yarn: 1.22.19
      pnpm: 7.1.7
    Relevant packages:
      next: 13.2.4
      eslint-config-next: 13.1.6
      react: 18.2.0
      react-dom: 18.2.0

Link to the code that reproduces this issue

https://www.digitalocean.com/community/questions/next-js-on-demand-revalidation-not-working-on-digitalocean-app-platform

To Reproduce

export default async function handler(req: NextApiRequest, res: NextApiResponse) { // Checking for available method if (req.method !== 'POST') { return res.status(404).json({ error: Invalid method ${req.method} }); }

// Checking body if (!req.body.subdomain) { return res.status(401).send({ error: 'Missing subdomain on body' }); }

// Revalidating route try { await res.revalidate(/${req.body.subdomain}); // Next.js method to recreate static pages

res.status(200).json({ ok: true, subdomain: req.body.subdomain, headers: req.headers });

} catch (error) { res.status(500).json({ error, headers: req.headers }); } }


- Create a page [subdomain] that will be static generated;
- Deploy the application to a DigitalOcean App Platform;
- Call the endpoint using `Postman` or equivalent. Send the `subdomain` on the body;
- Check for the update on the generated static;

### Describe the Bug

When deployed the same version on Vercel, or using it locally, is working normally, but deploying it to the DigitalOcean makes the `revalidate` do nothing, and don't even throw an error.
Adding the `unstable_onlyGenerated` as true on the options, makes it throw an empty error on DigitalOcean, but not on Vercel.

I returned the headers to check if there's something I can do, but I don't think so.

### Expected Behavior

Checking the source code on `node_modules/next/dist/esm/server/api-utils/node.js`, the revalidate checks for the host header and handles it differently if trusted or not.

The expected behavior is to work on both deployments, and not only on Vercel.

### Which browser are you using? (if relevant)

_No response_

### How are you deploying your application? (if relevant)

DigitalOcean
alessandrojcm commented 1 year ago

I don't know if this is related, but building with standalone: true and serving with node server.js on my local machine also has the same issue, it works sometimes after a server restart but that should not be the case.

AlexisWalravens commented 1 year ago

I don't know about Vercel but both on local and hosted with Docker the revalidate does not work.

I set a const export revalidate = 3600 the revalidation after 1h works but when I try to force with my revalidate endpoint it does nothing.

Edit: tried with both 13.2.4 and 13.2.5-canary.16

jfbaraky commented 1 year ago

For now, I'll leave the revalidate with only 5 seconds and wait for the fix :/

jfbaraky commented 1 year ago

Does someone have any update on this?

mwong-combo commented 1 year ago

Bump. Running into the same issue!

l-besenyei commented 1 year ago

I have a similar issue. On demand revalidation does not work on vercel. I get the error: Invalid response 200 No additional log messages on why. Using next 13.4.1 Locally it works as intended.

GiancarlosIO commented 1 year ago

Using nextjs 13.2.4 and getting an error when making a request to the revalidate endpoint 😢

2023-05-25T20:37:52.825Z    undefined   ERROR   Cannot find module 'next/dist/server/next-server.js'
Require stack:
- /var/task/___next_launcher.cjs
2023-05-25T20:37:52.825Z    undefined   ERROR   Did you forget to add it to "dependencies" in `package.json`?
RequestId: xxxxx-xxxx-xxxx-xxxxx Error: Runtime exited with error: exit status 1
Runtime.ExitError

It only happens in vercel, in local/development it works correctly 😭

agustints commented 7 months ago

Any updates on this?

I'm facing the same issue when deploying to Vercel, locally works as spected (pages router):

Error: Failed to revalidate /content/[slug]: Invalid response 200
    at z (/var/task/node_modules/next/dist/compiled/next-server/pages-api.runtime.prod.js:20:11496)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async o (/var/task/.next/server/pages/api/revalidate.js:1:650)
    at async K (/var/task/node_modules/next/dist/compiled/next-server/pages-api.runtime.prod.js:20:16545)
    at async U.render (/var/task/node_modules/next/dist/compiled/next-server/pages-api.runtime.prod.js:20:16981)
    at async r2.runApi (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:17:42106)
    at async r2.handleCatchallRenderRequest (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:17:36819)
    at async r2.runImpl (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:16:17133)
    at async r2.handleRequestImpl (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:16:16226)
    at async Server.<anonymous> (/var/task/___next_launcher.cjs:27:5)