HarmonyOS 关于动态import找不到模块的问题咨询

请问我新建了一个模块后,在动态import模块的时候出现:

ReferenceError: Cannot find module '@ohos/feature_search' imported from 'com.meiyou.hmapp/entry@uikit/ets/components/router/DynamicsRouter'.;

import代码如下:

await import(moduleName).then((result: ESObject) => {
  // 动态加载模块成功时,通过模块中的harInit接口加载页面
  result.harInit(pageName);
  isImportSucceed = true;
  /*if (FullScreenArray.includes(moduleName)) {
    isNeedFullScreen = false;
  }*/
}, (error: ESObject) => {
  // 动态加载模块失败时,打印错误日志
  LogUtils.error(LOGGER_TAG, "挂载失败:"+error);
});

其中moduleName=@ohos/feature_search

并且 @ohos/feature_search 模块已在oh_package.json里声明:

"dependencies": {
  "@ohos/feature_home": "file:../../feature/feature_home",
  "@ohos/feature_account": "file:../../feature/feature_account",
  "@ohos/feature_calendar": "file:../../feature/feature_calendar",
  "@ohos/feature_setting": "file:../../feature/feature_setting",
  "@ohos/feature_community": "file:../../feature/feature_community",
  "@ohos/feature_mine": "file:../../feature/feature_mine",
  "@ohos/feature_pregnancy": "file:../../feature/feature_pregnancy",
  "@ohos/feature_push": "file:../../feature/feature_push",
  "@ohos/uikit": "file:../../common/uikit",
  "@ohos/sdk": "file:../../common/sdk",
  "@ohos/feature_common": "file:../../feature/feature_common",
  "@ohos/dataorm": "2.2.2-rc.1",
  "@ohos/feature_upload": "file:../../feature/feature_upload",
  "@ohos/feature_tools": "file:../../feature/feature_tools",
  "@ohos/feature_search": "file:../../feature/feature_search"
}

并且在entry里的build-profile.json里也声明了如下:

"targets": [
{
  // 默认是正式环境
  "name": "default",
"runtimeOS": "HarmonyOS",
"output": {
  "artifactName":"harmonyos_meetyou_targets_product"
},
  "config": {
  "buildOption": {
    "arkOptions": {
      "runtimeOnly": {
        "packages": [
        "@ohos/feature_home",
        "@ohos/feature_account",
        "@ohos/feature_calendar",
        "@ohos/feature_community",
        "@ohos/feature_upload",
        "@ohos/feature_mine",
        "@ohos/feature_setting",
        "@ohos/uikit",
        "@ohos/sdk",
        "@ohos/feature_community",
        "@ohos/feature_pregnancy",
        "@ohos/feature_tools",
        "@ohos/feature_search"
        ]
      },
      "buildProfileFields": {
        "Env": "Product"
      }
    }
  }
}
}

疑问:为何会出现这种错误?是否是因为module变多了?

HarmonyOS
3天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
shlp

可以参考如下文档设置build-profile.json5

useNormalizedOHMUrl:

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-hvigor-build-profile-0000001778834297-V5

代码:

"products": [
{
  "name":
  "default", "signingConfig":
  "default", "compatibleSdkVersion":
  "5.0.0(12)", "runtimeOS":
  "HarmonyOS", "buildOption":
  {
    "strictMode":
    {
      "useNormalizedOHMUrl":
      true
    }
  }
}
]
分享
微博
QQ
微信
回复
3天前
相关问题
导入ohos相关模块找不到
6321浏览 • 1回复 待解决
HarmonyOS 找不到崩溃日志问题
256浏览 • 1回复 待解决
HarmonyOS 动态import so使用问题
42浏览 • 1回复 待解决
HarmonyOS 关于vp问题咨询
13浏览 • 1回复 待解决
HarmonyOS 关于import包引入问题
519浏览 • 1回复 待解决
关于数据缓存问题咨询
301浏览 • 1回复 待解决
HarmonyOS 关于router.back问题咨询
471浏览 • 1回复 待解决
HarmonyOS 找不到GestureRecognizer类
14浏览 • 1回复 待解决
HarmonyOS 找不到对应组件
260浏览 • 1回复 待解决
HarmonyOS 引用找不到方法
244浏览 • 1回复 待解决
关于系统定位缓存问题咨询
692浏览 • 1回复 待解决
关于动态创建组件销毁问题
245浏览 • 1回复 待解决