HarmonyOS 鸿蒙Next运行项目报错:Error message:cannot find record '&@hadss/hmrouter/Index&1.0.0-rc.11', please check the request path.'/data/sto
HarmonyOS 鸿蒙Next运行项目报错:Error message:cannot find record ‘&@hadss/hmrouter/Index&1.0.0-rc.11’, please check the request path.’/data/sto
自己的IDE版本为:
SDK为:API12
当运行项目后报如下错误,但是按提示修改了版本号为1.0.0-rc.10后提示报找不到1.0.0-rc.10的错误,请大家给出原因和解决办法
更多关于HarmonyOS 鸿蒙Next运行项目报错:Error message:cannot find record '&@hadss/hmrouter/Index&1.0.0-rc.11', please check the request path.'/data/sto的实战教程也可以访问 https://www.itying.com/category-93-b0.html
【背景知识】
DevEco Studio升级更新:下载与安装DevEco Studio。
【问题定位】
IDE版本为:5.0.4release,但是API版本:12,可能是依赖版本不匹配。
【分析结论】
- 增量构建残留:修改@hadss/hmrouter模块版本号后(如从1.0.0-rc.11改为1.0.0-rc.10),旧版本构建缓存未被清除,导致系统仍尝试用旧版本号寻址文件。
- 依赖版本不匹配:@hadss/hmrouter的1.0.0-rc.10版本可能未正确发布到依赖仓库,或本地oh-package.json5未正确配置远程仓库地址,导致无法下载该版本。
- IDE缓存未同步:DevEco Studio 5.0.4的缓存机制可能未及时更新模块版本信息,导致路径解析错误。
【修改建议】
- 清理构建残留:
- 操作步骤:在项目中执行Build>Clean Project清除构建缓存;手动删除工程目录下的build、node_modules、.arkui-x(若有)文件夹;重启IDE,确保缓存完全释放。
- 修复依赖管理:
- 检查版本可用性:确认远程仓库(如Ohpm私仓)中是否存在1.0.0-rc.10或1.0.0-rc.11版本:
若版本不存在,需联系模块维护者重新发布或还原到可用版本。ohpm info [@hadss](/user/hadss)/hmrouter
- 修正依赖配置:在oh-package.json5中明确指定有效版本号,并检查仓库配置:
"dependencies": { "[@hadss](/user/hadss)/hmrouter": "1.0.0-rc.11" // 确保该版本在仓库中存在 }
- 检查版本可用性:确认远程仓库(如Ohpm私仓)中是否存在1.0.0-rc.10或1.0.0-rc.11版本:
- 强制更新依赖:
- 重新安装模块:在终端执行以下命令强制刷新依赖:
ohpm install [@hadss](/user/hadss)/hmrouter --force
- 重新安装模块:在终端执行以下命令强制刷新依赖:
【总结】
该问题主要由于模块版本号变更后增量构建导致的缓存残留,或者是版本号不匹配引起的。
更多关于HarmonyOS 鸿蒙Next运行项目报错:Error message:cannot find record '&@hadss/hmrouter/Index&1.0.0-rc.11', please check the request path.'/data/sto的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
可以试试使用override指定版本号
重新安装依赖
在终端执行 ohpm install @hadss/hmrouter@1.0.0-rc.11
。
检查 oh-package.json5
中版本号是否与安装命令一致
有要学HarmonyOS AI的同学吗,联系我:https://www.itying.com/goods-1206.html
你可以参考一下我的配置:
- 在文件
oh-package.json5
中修改为这样试试:
{
"dependencies": {
"@hadss/hmrouter": "^1.1.0-beta.0"
}
}
在 hvigor/hvigor-config.json5
中这样配置:
{
"modelVersion": "5.0.5",
"dependencies": {
"@hadss/hmrouter-plugin": "^1.0.0-rc.11"
},
"execution": {
// "analyze": "normal", /* Define the build analyze mode. Value: ["normal" | "advanced" | false ]. Default: "normal" */
// "daemon": true, /* Enable daemon compilation. Value: [true | false ]. Default: true */
// "incremental": true, /* Enable incremental compilation. Value: [true | false ]. Default: true */
// "parallel": true, /* Enable parallel compilation. Value: [true | false ]. Default: true */
// "typeCheck": false, /* Enable typeCheck. Value: [true | false ]. Default: false */
},
"logging": {
// "level": "info" /* Define the log level. Value: ["debug" | "info" | "warn" | "error" ]. Default: "info" */
},
"debugging": {
// "stacktrace": false /* Disable stacktrace compilation. Value: [true | false ]. Default: false */
},
"nodeOptions": {
// "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/
// "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/
}
}
- 初始化的话你可以看一下另外一个博主的方法,也可以看一下这种初始化方式:通过启动框架初始化
@Sendable
export default class HMRouterInitStartupTask extends StartupTask {
constructor() {
super();
}
async init(context: common.AbilityStageContext) {
// add task to init HMRouter
HMRouterMgr.init({
context: context
});
HMRouterMgr.openLog('DEBUG');
console.log('========111111111');
}
onDependencyCompleted(dependence: string, result: Object): void {
hilog.info(0x0000, 'testTag', 'StartupTask_001 onDependencyCompleted, dependence: %{public}s, result: %{public}s',
dependence, JSON.stringify(result));
}
}
参考文档:
[@ohos.app.appstartup.StartupConfigEntry (启动框架配置)-Stage模型能力的接口-ArkTS API-Ability Kit(程序框架服务)-应用框架 - 华为HarmonyOS开发者](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-app-appstartup-startupconfigentry#startupconfigentryonconfig)
不喜欢用HMRouter,用了出现好多怪问题
HMRouter没有初始化,请按照以下方式初始化:
export default class EntryAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
// 日志开启需在init之前调用,否则会丢失初始化日志
HMRouterMgr.openLog("INFO")
HMRouterMgr.init({
context: this.context
})
}
}
这个错误表明鸿蒙Next在运行项目时无法找到指定的模块记录。错误信息中提到的’&@hadss/hmrouter/Index&1.0.0-rc.11’路径不存在或配置有误。检查项目中以下内容:
- oh-package.json5配置是否正确
- 模块依赖版本是否匹配
- 模块路径是否存在拼写错误
- 确保所有依赖已正确安装
该错误通常由模块路径配置问题或版本不匹配导致。
这个错误表明项目依赖的hmrouter模块版本在本地仓库中不存在。主要原因可能是:
- 项目配置的依赖版本(1.0.0-rc.11)与本地SDK中的版本不匹配
- SDK未正确安装或配置
解决方法:
-
检查项目中的oh-package.json5文件,确认依赖声明是否正确
-
清理并重新安装依赖:
- 删除项目中的oh_modules目录
- 运行ohpm install命令重新安装依赖
-
如果问题依旧,可以尝试:
- 更新IDE和SDK到最新版本
- 检查网络连接是否正常
- 确认ohpm仓库配置正确
建议先尝试将依赖版本调整为SDK中实际存在的版本,然后清理重装依赖。