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
赞
收藏 0
回答 1
待解决
相关问题
关于IDE文档中中的kit manager 找不到的问题
5150浏览 • 1回复 待解决
HarmonyOS 关于第三方仓库找不到库的问题
18浏览 • 1回复 待解决
导入ohos相关模块都找不到
6321浏览 • 1回复 待解决
HarmonyOS 找不到崩溃日志问题
256浏览 • 1回复 待解决
HarmonyOS 动态import so使用问题
42浏览 • 1回复 待解决
HarmonyOS 关于vp的问题咨询
13浏览 • 1回复 待解决
HarmonyOS 关于import包引入问题
519浏览 • 1回复 待解决
在学习arkts基础知识,找不到模块怎么解决?
2617浏览 • 1回复 待解决
HarmonyOS 关于CustomDialogController关闭的问题咨询
66浏览 • 1回复 待解决
HarmonyOS HSP模块间能通过动态import依赖解耦吗
40浏览 • 0回复 待解决
#鸿蒙通关秘籍#如何配置动态import实现 HarmonyOS 模块的按需加载?
205浏览 • 1回复 待解决
关于数据缓存问题咨询
301浏览 • 1回复 待解决
HarmonyOS 关于router.back问题的咨询
471浏览 • 1回复 待解决
HarmonyOS 找不到GestureRecognizer类
14浏览 • 1回复 待解决
HarmonyOS 找不到对应组件
260浏览 • 1回复 待解决
HarmonyOS 引用找不到方法
244浏览 • 1回复 待解决
鸿蒙如何设置通过变量动态import模块,实现有的编译类型下模块可动态导入,有些编译类型模块不可动态导入
464浏览 • 1回复 待解决
HarmonyOS 通过RouterModule动态路由加载在方式,提示找不到对应在module
16浏览 • 1回复 待解决
HarmonyOS 关于动态设置组件宽度的问题
417浏览 • 1回复 待解决
HarmonyOS 模块加载:HSP模块下,使用动态import,为何需要在工程目录下配置dependencies
29浏览 • 1回复 待解决
HarmonyOS 关于XComponent组件内容填充的问题咨询
27浏览 • 1回复 待解决
关于系统定位缓存问题咨询
692浏览 • 1回复 待解决
#鸿蒙通关秘籍#如何使用动态import实现鸿蒙应用模块的解耦?
101浏览 • 1回复 待解决
HarmonyOS 关于获取录音音频的时长的问题咨询
75浏览 • 1回复 待解决
关于动态创建的组件销毁问题
245浏览 • 1回复 待解决
可以参考如下文档设置build-profile.json5
useNormalizedOHMUrl:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/ide-hvigor-build-profile-0000001778834297-V5
代码: