HarmonyOS 鸿蒙Next中RN:react-native-harmony+taro项目运行时报@unimodules/react-native-adapter的错误

HarmonyOS 鸿蒙Next中RN:react-native-harmony+taro项目运行时报@unimodules/react-native-adapter的错误

在鸿蒙侧运行项目时报"The “UMNativeModulesProxy” native module is not exported through NativeModules; verify that @unimodules/react-native-adapter’s native code is linked properly"的错

cke_1383.png


更多关于HarmonyOS 鸿蒙Next中RN:react-native-harmony+taro项目运行时报@unimodules/react-native-adapter的错误的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

麻烦您提供一下RN和Taro的版本号和依赖等信息

更多关于HarmonyOS 鸿蒙Next中RN:react-native-harmony+taro项目运行时报@unimodules/react-native-adapter的错误的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在鸿蒙Next中使用react-native-harmony+Taro项目报@unimodules/react-native-adapter错误,是因为该依赖为React Native生态模块,不兼容鸿蒙环境。鸿蒙Next的React Native实现基于react-native-harmony,需要移除或替换第三方依赖中与原生平台绑定的模块。检查项目package.json,删除或替换@unimodules相关依赖,改用鸿蒙支持的纯JS实现方案。

这个错误表明项目中的@unimodules/react-native-adapter模块没有正确链接到原生代码中。对于HarmonyOS Next环境下的React Native开发,需要特别注意以下几点:

  1. 确保在项目根目录的oh-package.json中正确声明了依赖项:
"dependencies": {
  "[@unimodules](/user/unimodules)/react-native-adapter": "^x.x.x"
}
  1. 检查native模块是否正确注册。在鸿蒙环境下,需要确保在entry/src/main/ets/entryability/EntryAbility.ts文件中注册了所需的原生模块。

  2. 尝试重新链接原生模块:

  • 删除node_modules和oh_modules目录
  • 重新运行npm install
  • 执行ohpm install
  • 重新构建项目
  1. 如果问题仍然存在,可能需要检查@unimodules/react-native-adapter是否完全兼容HarmonyOS环境,有些React Native原生模块可能需要针对鸿蒙进行适配。
回到顶部