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
相关产品推荐
相关产品推荐

