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

使用Clerk实现授权时遇导入错误:'SWRConfig'未从'swr'导出

解决Clerk导入SWRConfig失败的问题

错误信息:

./node_modules/@clerk/shared/dist/react/index.mjs
Attempted import error: 'SWRConfig' is not exported from 'swr' (imported as 'SWRConfig').

这个问题是因为你安装的swr版本和Clerk依赖的版本不兼容导致的。Clerk目前依赖swr v1.x版本,而如果你装了swr v2+,会发现SWRConfig的导出方式已经变更,所以出现导入失败。

解决步骤:

  • 卸载当前的swr,安装兼容的v1版本:

    # npm
    npm uninstall swr && npm install swr@^1.3.0
    
    # yarn
    yarn remove swr && yarn add swr@^1.3.0
    
  • 清除依赖缓存并重启开发服务:

    rm -rf node_modules package-lock.json # 若用yarn则删除yarn.lock
    npm install # 或yarn install
    # 重启你的开发服务器,比如执行npm start
    
  • 验证版本:打开package.json,确认swr的版本号以1.开头,确保和Clerk的依赖要求匹配。

如果还是有问题,可以查看@clerk/shared包的package.json文件里的peerDependencies字段,确认它指定的swr版本范围,安装对应的版本即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 19:55:55