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

Reanimated报错valueUnpacker非worklet及main未注册问题求助

解决方案

一、修复valueUnpacker is not a worklet错误(Reanimated 相关)

这个问题大概率是Reanimated的配置或版本兼容问题,按以下步骤排查:

  • 检查Babel插件配置:
    打开项目根目录的babel.config.js,确保react-native-reanimated/plugin是插件数组的最后一项,配置示例:
    module.exports = {
      presets: ['module:metro-react-native-babel-preset'],
      plugins: [
        // 其他插件放在前面
        'react-native-reanimated/plugin',
      ],
    };
    
  • 清空Metro缓存:
    执行命令强制重置缓存:
    npx react-native start --reset-cache
    
  • 校验版本兼容性:
    确认Reanimated版本和你的React Native版本匹配(比如RN 0.7x对应Reanimated 3.x),版本不兼容的话,重新安装适配版本:
    npm uninstall react-native-reanimated
    npm install react-native-reanimated@3.x # 替换为对应适配的版本号
    
  • 清理Android原生构建缓存:
    cd android && ./gradlew clean && cd ..
    

二、修复"main" has not been registered错误

这个错误可能是Reanimated问题引发的连锁故障,也可能是项目入口配置问题:

  • 确认入口文件的AppRegistry注册:
    打开项目的index.js(或index.tsx),确保存在正确的注册代码:
    import { AppRegistry } from 'react-native';
    import App from './App';
    import { name as appName } from './app.json';
    
    AppRegistry.registerComponent(appName, () => App);
    
  • 检查Metro启动路径:
    关闭所有正在运行的Metro进程,回到项目根目录重新启动:
    npx react-native start
    
  • 排查模块加载错误:
    查看终端的完整报错日志,找是否有前置的模块导入失败、依赖缺失等错误,这些问题会导致AppRegistry无法被正常调用。

三、完整验证流程

  1. 彻底清理项目依赖和缓存:
    rm -rf node_modules && rm package-lock.json && npm install
    npx react-native start --reset-cache
    
  2. 重新构建并运行Android项目:
    npm run android
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 17:17:12