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

安装NextAuth Beta版后出现TypeError: r is not a function问题求助

解决NextAuth Beta版与Next.js的TypeError: r is not a function错误

修复步骤

1. 排查版本兼容性

Beta版NextAuth常存在版本适配问题,先确认当前Next.js版本是否符合该Beta版的要求:

  • 升级Next.js到最新稳定版:
    npm install next@latest
    # 或使用yarn
    yarn add next@latest
    
  • 若升级后问题仍存在,可尝试降级Next.js到该Beta版明确兼容的版本号

2. 彻底清除缓存与依赖

仅删除node_modules不足以解决缓存残留问题,执行以下操作:

  • 删除Next.js编译缓存:
    rm -rf .next
    
  • 清除npm/yarn缓存:
    # npm
    npm cache clean --force
    # yarn
    yarn cache clean
    
  • 重新安装依赖:
    rm -rf node_modules package-lock.json yarn.lock
    npm install
    # 或 yarn install
    

3. 检查NextAuth配置文件

Beta版NextAuth的API可能有破坏性变更,核对配置文件:

  • 针对App Router:检查app/api/auth/[...nextauth]/route.js,确保authOptions结构正确,比如providers数组配置无误、session策略设置符合Beta版要求
  • 针对Pages Router:检查pages/api/auth/[...nextauth].js,移除已废弃的配置项,替换为Beta版新API

4. 切换到稳定版NextAuth

若Beta版的问题无法快速定位,可暂时切换到稳定版规避:

npm uninstall next-auth
npm install next-auth@latest

之后根据稳定版文档调整配置代码


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 09:52:45