You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NextJS 13 Beta版本ISR(增量静态生成)功能失效问题求助

解决NextJS 13 App Router中ISR(增量静态生成)不生效的问题

核心问题分析

你的代码使用axios发起数据请求,但Next.js的ISR机制仅对框架内置的fetch API生效,axios无法识别页面级或请求级的revalidate配置。此外还需排查项目配置中的关键限制项。

具体修复步骤

  • 替换axios为Next.js内置fetch
    改用框架原生的fetch API,它会自动识别页面级的revalidate配置,也可在请求中单独配置:

    import Card from "@/components/Card";
    
    export const revalidate = 15;
    
    const AllCards = async () => {
      const url = 'http://localhost:3001/cards';
      const res = await fetch(url);
      const { data: cards } = await res.json();
      return (
        <main>
          <div className='text-3xl font-bold underline text-center mb-4 mt-4'>
            All Cards
          </div>
          <div className='flex flex-wrap justify-center gap-2'>
            {cards.map(c => <Card vanity={c.vanity} art={c.art} id={c.id} />)}
          </div>
        </main>
      );
    }
    
    export default AllCards;
    
  • 检查next.config.js的output配置
    如果你的next.config.js中设置了output: 'export',静态导出模式不支持ISR功能,需移除该配置:

    // next.config.js
    /** @type {import('next').NextConfig} */
    const nextConfig = {
      // 移除 output: 'export' 配置项
    }
    
    module.exports = nextConfig;
    
  • 升级NextJS到稳定版
    你使用的13 Beta版本存在不少已知兼容性问题,ISR功能在早期App Router Beta中可能存在bug,建议升级到13.x稳定版本:

    npm install next@latest react@latest react-dom@latest
    

验证ISR生效

重新执行npm run build,若ISR配置生效,终端输出中该页面会显示(ISR: 15s)标识,而非空白。启动生产环境服务器npm start后,页面会在15秒内返回缓存内容,之后自动触发增量更新。

内容的提问来源于stack exchange,提问作者kar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 09:15:34