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

NextJS构建报错:@hookstate/core无useState导出成员求助

解决 "@hookstate/core" 无导出成员 'useState' 的问题
  • 先排查版本变更问题:
    HookState从v4版本开始移除了useState导出,改用hookstate方法作为替代。如果你的依赖自动升级到了v4+,就会触发这个报错。
    原来的代码:

    import { useState } from '@hookstate/core'
    const state = useState({ count: 0 })
    

    需要改成:

    import { hookstate } from '@hookstate/core'
    const state = hookstate({ count: 0 })
    

    要是不想改代码,可以锁定旧版本,在package.json里把@hookstate/core的版本指定为v3.x,比如"@hookstate/core": "^3.0.0",然后执行npm install重新安装依赖。

  • 清理缓存试试:
    有时候依赖缓存或Next.js构建缓存会导致版本不匹配,执行以下命令:

    npm cache clean --force
    rm -rf node_modules package-lock.json
    npm install
    npm run build --clean
    
  • 检查导入拼写:
    确认没有写错包名或者useState的大小写,比如别把@hookstate/core写成hookstate/core,也别把useState写成UseState。

内容的提问来源于stack exchange,提问作者Đỗ Duy Đoàn

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 23:05:21