Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

408
Vistas
NextJS - TypeError: res.unstable_revalidate is not a function

I try to use a brand new feature released in NextJS v.12.1 https://deepinder.me/nextjs-on-demand-isr. The API itself works fine. I can reach it. But in exchange it returns 500 error that says res.unstable_revalidate is not a function. It does not work either over dev (next server && next dev) run or production one (next build && next start).

This is the api endpoint:

// ./api/misc/revalidate

const revalidateCache = async (_, res) => {
    console.log(res.unstable_revalidate, 'TEST REVALIDATE'); // res.unstable_revalidate is undefined here :( 

    try {
        await res.unstable_revalidate('/');

        return res.json({ revalidated: true });
    } catch (err) {
        return res.status(500).send(`Error revalidating: ${err}`);
    }
};

export default revalidateCache;

This is the invoke:

// ./apps/client/services/server
const getRevalidate = async () => {
    await fetch('/api/misc/revalidate');
};

export default getRevalidate;

View layer that I call from:

// .src/pages/index.js

// ...some code here

const HomePage = ({ page, legacy }) => {
    const handleClick = () => {
        getRevalidate();
    };

    return (
        <div className={styles.homeRoot}>
            <button onClick={handleClick}>REVALIDATE</button>
        </div>
    );
};

UPD: I use express to handle API abstration.


import express from 'express';

import revalidateCacheApi from './api/misc/revalidate';

export default app => {
    // ...some code here

    app.use('/api/misc/revalidate', revalidateCacheApi);
};


about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

NVM. It was an issue with my local server. I use advanced set up with two independent instances (:3000 and :4000) spinning in the memory.

The way I designed API above suppose to call it over :4000 server. Which is in fact Express server (obviously does not has NextJS internal API to purge the cache).

So I moved the call to the pages/api/revalidate and up to :3000 server.

Works fine:

// ./src/pages/server/revalidate.js

const getRevalidate = async () => {
    await fetch('/api/revalidate');
};

export default getRevalidate;

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda