在 DevEco Studio 4.0 中 , 创建 API 8 的 鸿蒙应用 ,
发现 在进入界面后 , 首次编译 , 就出现报错的情况 , 报错信息如下 :
D:\001_Develop\053_Huawei\nodejs\nodejs-16.20.1\npm.cmd install --fetch-retry-mintimeout=10000 --fetch-retry-maxtimeout=15000 --fetch-retries=1 npm ERR! code ETARGET npm ERR! notarget No matching version found for @ohos/hypium@1.0.11. npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package version that doesn’t exist.
npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\octop\AppData\Local\npm-cache_logs\2024-05-28T07_13_19_279Z-debug-0.log
Process finished with exit code 1
翻译后内容如下 :
npm ERR!没有找到 @ohos/hypium@1.0.11的匹配版本。 npm ERR!在大多数情况下,您或您的一个依赖项正在请求 npm ERR!不要瞄准不存在的包版本。
上述报错的核心报错信息是
npm ERR! notarget No matching version found for @ohos/hypium@1.0.11.
翻译后就是 没有找到与 @ohos/hypium@1.0.11 版本匹配的软件包 ;
该 DevEco Studio 4.0 开发环境 , 匹配的是 API 9 , 如果创建 API 8 的相关应用 , 会出现一些匹配问题 , 本次报错就是该问题 ;
在项目根目录下的 build-profile.json5 配置中 , 配置的 SDK 版本都是 API 8 版本 ;
完整配置如下 :
{
"app": {
"signingConfigs": [],
"compileSdkVersion": 8,
"compatibleSdkVersion": 8,
"products": [
{
"name": "default",
"signingConfig": "default",
}
],
"buildModeSet": [
{
"name": "debug",
},
{
"name": "release"
}
]
},
"modules": [
{
"name": "entry",
"srcPath": "./entry",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}
但是在 项目根目录下的 package.json 包配置中 , 配置的 @ohos/hypium 版本为 1.0.11 , 这是 API 9 使用的版本 , 该版本对于 API 8 来说有点高 ;
将 @ohos/hypium 版本改为 1.0.5 与 API 8 正好匹配 ;
package.json 包配置 完整带代码 :
{
"name": "myapplication",
"version": "1.0.0",
"ohos": {
"org": "huawei",
"buildTool": "hvigor",
"directoryLevel": "project"
},
"description": "example description",
"repository": {},
"license": "ISC",
"dependencies": {
"@ohos/hypium": "1.0.11",
"@ohos/hvigor": "3.0.9",
"@ohos/hvigor-ohos-plugin": "3.0.9"
}
}
在 package.json 包配置 中 , 将 将 @ohos/hypium 版本改为 1.0.5 , 设置完毕后 , 点击右上角的 Sync Now 同步按钮 , 重新开始编译 ;
{
"name": "myapplication",
"version": "1.0.0",
"ohos": {
"org": "huawei",
"buildTool": "hvigor",
"directoryLevel": "project"
},
"description": "example description",
"repository": {},
"license": "ISC",
"dependencies": {
"@ohos/hypium": "1.0.5",
"@ohos/hvigor": "3.0.9",
"@ohos/hvigor-ohos-plugin": "3.0.9"
}
}
同步完成后 , 项目编译成功 ;