HarmonyOS鸿蒙Next中打har包后无法引用,does not provide an export name 'JSBind'

HarmonyOS鸿蒙Next中打har包后无法引用,does not provide an export name ‘JSBind’ 自制har包,包中调用了aki的jsbind接口。报

Error message:the requested module '@normalized:Y&&&m2b_oh.so/index&' does not provide an export name 'JSBind' which imported by '&m2b_oh/src/main/ets/components/RecorderController&1.0.0'

如何解决

cke_586.png

C++的index.d.ts

export const startScreenCapture:(configStr:string,isMicrophone:boolean)=>number;
export const stopScreenCapture:()=>number;
export class JSBind {
  static bindFunction: (name: string, func: Function) => number;
  static unbindFunction:(name:string)=> number;
}

更多关于HarmonyOS鸿蒙Next中打har包后无法引用,does not provide an export name 'JSBind'的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

【解决方案】

“module xxx does not provide an export name xxx which imported by xxx”,这类错误通常是运行时某个类/方法没有export引起的。可以检查以下几点:

  1. 检查报错的类/方法是否export(对外暴露)。
  2. 检查类/方法所在的类库是否正确被加载。
  3. 若是HarmonyOS提供的类/方法,检查使用的类/方法是否在当前运行环境的操作系统中具备,检查使用的类/方法在当前运行的设备中是否支持。同理,若是自定义的类库,检查类库的版本是否最新(是否包含报错的类/方法)。
  4. HAR包’@normalized:Y&&&m2b_oh.so/index&‘是否未配置consumer-rules.txt,开启混淆后导致HAR包’&m2b_oh/src/main/ets/components/RecorderController&1.0.0’引用方法时报错。HAR包’@normalized:Y&&&m2b_oh.so/index&'可以参考ArkGuard混淆开启指南配置consumer-rules.txt。

更多关于HarmonyOS鸿蒙Next中打har包后无法引用,does not provide an export name 'JSBind'的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS Next中,当HAR包无法引用JSBind时,可能由于以下原因:

  1. HAR包的oh-package.json5中未正确声明JSBind模块的导出路径。
  2. 模块的index.ets文件缺少export { JSBind } from './path/to/module'语句。
  3. 依赖的HAR包未在项目的oh-package.json5中正确配置。

检查HAR包的导出配置,确保模块路径正确且已声明为导出项。

问题在于HAR包中的JSBind导出未被正确识别。检查index.d.ts文件,确保JSBind类已正确定义为export,且模块路径与引用一致。在HAR包的oh-package.json5中,确认exports字段包含JSBind的导出路径,例如:

"exports": {
  ".": "./src/main/ets/index.ts",
  "./jsbind": "./src/main/cpp/types/index.d.ts"
}

在引用模块时使用完整路径:

import { JSBind } from 'your-har-package/jsbind';

重新构建HAR包并清理项目缓存,确保依赖更新。若使用C++原生代码,验证NAPI模块的符号导出与声明文件匹配。

回到顶部