HarmonyOS 鸿蒙Next 引用cheerio包调试编译报错

HarmonyOS 鸿蒙Next 引用cheerio包调试编译报错 依赖如下

"dependencies": {
   "@ohos/hypium": "1.0.1",
   "@ohos/hvigor": "1.1.6",
   "@ohos/hvigor-ohos-plugin": "1.1.6",
   "cheerio": "v1.0.0-rc.12",
   "dayjs": "1.8.21"
 }

引用如下

import * as cheerio from "cheerio"

function dealWhitHtml(html){
   const $ = cheerio.load(html)
   datejs.isDayjs('');
   let str=$( '.videos-list').html()
   logStr(str)
}

编译调试时报错:

"M:\Program Files\nodejs\node.exe" D:\Harmony\player\node_modules\@ohos\hvigor\bin\hvigor.js --mode module -p module=entry assembleHap
> hvigor Finished :entry:PreBuild... after 437 ms
> hvigor Finished :entry:LegacyMergeProfile... after 3 ms 700 μs
> hvigor Finished :entry:LegacyMakePackInfo... after 1 ms 930 μs
> hvigor Finished :entry:BuildNativeWithCmake... after 1 ms 250 μs
> hvigor Finished :entry:BuildNativeWithNinja... after 1 ms 260 μs
> hvigor Finished :entry:ProcessLibs... after 8 ms 190 μs
> hvigor Finished :entry:LegacyGenerateJsManifest... after 56 ms
> hvigor Finished :entry:LegacyProcessProfile... after 232 ms
> hvigor Finished :entry:LegacyCompileResource... after 232 ms
> hvigor Finished :entry:GenerateLoaderJson... after 19 ms
> hvigor ERROR: Failed :entry:LegacyCompileETS... 
> hvigor ERROR: A problem occurred in entry module:
        ERROR: Cause: Tools execution failed.
ETS:ERROR File: D:/Harmony/player/node_modules/cheerio-select/lib/index.d.ts:1:15
',' expected.

ETS:ERROR File: D:/Harmony/player/node_modules/htmlparser2/lib/index.d.ts:2:23
',' expected.

ETS:ERROR File: D:/Harmony/player/node_modules/htmlparser2/lib/index.d.ts:4:27
',' expected.

ETS:ERROR File: D:/Harmony/player/node_modules/htmlparser2/lib/index.d.ts:32:37
',' expected.

COMPILE RESULT:FAIL {ERROR:4} 
        ERROR: Solution: Please check the message from tools.

错误位置如下

错误位置1

错误位置2


更多关于HarmonyOS 鸿蒙Next 引用cheerio包调试编译报错的实战教程也可以访问 https://www.itying.com/category-93-b0.html

9 回复

模块内部的报错,检查一下包是不是哪里写错了

更多关于HarmonyOS 鸿蒙Next 引用cheerio包调试编译报错的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


楼主有解决吗?我同样问题,换成v1.0.0-rc.10 版本虽然没有报错,但是在引用的页面都会直接白屏,API8 的

没有,目前看了并不兼容,

找HarmonyOS工作还需要会Flutter技术的哦,有需要Flutter教程的可以学学大地老师的教程,很不错,B站免费学的哦:BV1S4411E7LY/?p=17

如果你是开发开源鸿蒙应用的话社区有相应的HTML解析工具,手机应用目前无法引用就是了,

找HarmonyOS工作还需要会Flutter的哦,有需要Flutter教程的可以学学大地老师的教程,很不错,B站免费学的哦:BV1S4411E7LY/?p=17

哎,他java又砍掉了,不然用java解析也好啊,

欢迎开发小伙伴们进来帮帮楼主

针对帖子标题“HarmonyOS 鸿蒙Next 引用cheerio包调试编译报错”的问题,这里给出直接相关的回答:

在HarmonyOS鸿蒙Next系统中,如果你尝试引用cheerio包并遇到调试编译错误,这通常是因为cheerio包是为Node.js环境设计的,而HarmonyOS主要基于其自研的ArkUI和JS框架,与标准的Node.js环境存在差异。

由于HarmonyOS的生态系统与Node.js不完全兼容,直接引用为Node.js设计的npm包(如cheerio)可能会遇到问题。这包括但不限于API不兼容、模块解析错误或运行时异常。

解决这类问题的一种方法是寻找HarmonyOS兼容的替代库或工具,这些库或工具应专为HarmonyOS设计或经过适配以确保兼容性。此外,你也可以考虑使用HarmonyOS提供的原生API或组件来实现类似功能。

如果上述方法仍然无法解决问题,建议检查cheerio包的依赖关系和HarmonyOS的文档,以确保没有遗漏任何关键的配置或依赖项。同时,确保你的开发环境(包括SDK和工具链)已更新到最新版本,以支持最新的HarmonyOS特性和修复。

如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html

回到顶部