写在前面

本文整理了本人在进行方舟运行时编译时遇到的各种错误。我在尝试解决这些错误时,首先使用了AI工具,然后在网络上试着查询相关的解决方法,但是很遗憾相关资料较少,无论哪一个都不能简单地解决问题。因此本人将遇到的一些问题都整理在这个文档中,为将来可能遇到相同或相关问题的人提供参考。
本文中会给出比较完整的错误内容,确保本文容易被搜索。
由于内容较多,推荐查看目录寻找你遇到的具体问题。

注意

本文所进行的编译过程请参考方舟运行时指南,运行时间最晚为2026年1月18日,运行环境为wsl2的Ubuntu22.04,所整理的问题都是在并未对源码做出任何修改的(默认)情况下运行以下编译命令时遇到的:

./build.sh --product-name rk3568

注意根目录下的build.sh其实是一个指向./build/build_scripts/build.sh的软链接。
建议

  • 按照编译过程中的指示将shell更换为bash:
[1]:Open the Terminal tool and execute the following command: sudo dpkg-reconfigure dash \n [2]:Enter the password and select <no> 
  • 使用要求的的Node.js版本14.21.1(版本不匹配会被直接退出;ohpm会警告建议使用18.x.x版本,但根据脚本其实用不了)。
  • 升级npm。(虽然没有证据,但感觉我的npm版本过低也造成了一些问题)
  • 在开始编译前可以参考ArkCompiler开发指导,先运行以下代码下载prebuild工具:
./build/prebuilts_download.sh

缺少xx组件 find component xxx failed(除hiprofiler)

由于OpenHarmony源码的拉取过程较长,很可能出现缺少某关键组件的问题。
这种情况下AI一般会建议你去\out\preloader\ohos-sdk\parts.json查找组件,然后用find grep等文件查找命令查找组件位置。然而parts.json中不能直接看出组件的位置和名称,使用find等命令查找又极其缓慢,在repo命令中直接使用缺少的组件名字也无法直接拉取到仓库,即使直接用git拉取对应组件也需要提前知道组件在项目中所在的位置。
以下给出一些快速定位缺少的组件的具体位置、以及使用repo重新拉取的方法。

错误信息案例(napi)

[OHOS ERROR] [LOAD] Traceback (most recent call last):
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR] [LOAD]     return func(*args, **kwargs)
[OHOS ERROR] [LOAD]            ^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/modules/ohos_build_module.py", line 67, in run
[OHOS ERROR] [LOAD]     super().run()
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/modules/interface/build_module_interface.py", line 66, in run
[OHOS ERROR] [LOAD]     self._load()
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/modules/ohos_build_module.py", line 89, in _load
[OHOS ERROR] [LOAD]     self.loader.run()
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/services/interface/load_interface.py", line 50, in run
[OHOS ERROR] [LOAD]     self.__post_init__()
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/services/loader.py", line 126, in __post_init__
[OHOS ERROR] [LOAD]     self.parts_config_info = load_ohos_build.get_parts_info(
[OHOS ERROR] [LOAD]                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/util/loader/load_ohos_build.py", line 956, in get_parts_info
[OHOS ERROR] [LOAD]     _output_parts_info(parts_config_dict,
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/util/loader/load_ohos_build.py", line 774, in _output_parts_info
[OHOS ERROR] [LOAD]     check_subsystem_and_component(parts_info_output_path, skip_partlist_check)
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/util/loader/load_ohos_build.py", line 697, in check_subsystem_and_component
[OHOS ERROR] [LOAD]     compare_subsystem_and_component(subsystem_name, components_name, subsystem_components_whitelist_info,
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/util/loader/load_ohos_build.py", line 663, in compare_subsystem_and_component
[OHOS ERROR] [LOAD]     raise Exception(message)
[OHOS ERROR] [LOAD] Exception: find component napi failed, please check it in /mnt/f/openharmony_source/out/preloader/ohos-sdk/parts.json.
[OHOS ERROR] [LOAD]

[OHOS ERROR] [LOAD] Code:        0000
[OHOS ERROR] [LOAD]
[OHOS ERROR] [LOAD] Reason:      find component napi failed, please check it in /mnt/f/openharmony_source/out/preloader/ohos-sdk/parts.json.
[OHOS ERROR] [LOAD]
[OHOS ERROR] [LOAD] Error Type:  UNKNOWN ERROR TYPE
[OHOS ERROR] [LOAD]
[OHOS ERROR] [LOAD] Description: NO DESCRIPTION
[OHOS ERROR] [LOAD]
[OHOS ERROR] [LOAD] Solution:    NO SOLUTION
[OHOS ERROR] [LOAD]

使用repo命令直接查找仓库信息

repo list | grep -i 组件名

这里以我自己缺少的napi组件为例,可以较快找到napi的位置:
napi组件位置在parts.json中随便找一个组件用这个方法也能很快确定位置:
随机选择一个组件
结果

在IDE中打开build文件夹直接搜索

其实这个还更快一点,就是比较原始。
打开自己常用的编译器,打开根目录下的build文件夹,直接全局搜索组件名即可,以下以vscode为例:

或者直接在这个build\component_compilation_whitelist.json中搜索应该也是一样的,可以很快找到对应的组件所在位置。

拉取缺少的组件仓库

确定缺少的仓库所在位置之后,就可以进行拉取了。(建议先到文件目录检查是否缺失组件,否则有可能是配置问题)
如果仓库文件本身不存在可以直接拉取:

repo sync 组件目录

比如napi组件:

repo sync foundation/arkui/napi

如果之前已经部分拉取过或拉取发生其他错误(还是以napi为例):

rm -rf foundation/arkui/napi # 删除原有目录
rm -rf .repo/projects/foundation/arkui/napi.git # 清除缓存
rm -rf .repo/project-objects/arkui_napi.git # 可能的其他缓存
repo sync foundation/arkui/napi # 重新同步

如果拉取后文件夹内依然没有或缺少文件,可能是git状态异常,使用git status判断问题然后按具体情况解决即可。

find component hiprofiler failed

这个问题个人感觉相对比较复杂,出现是因为不同的原因,还是要看具体的错误信息来判断,观察到的共性是该错误都源于缺乏一些prebuilts中特定的包或模块,以下给出几个本人遇到的相关问题。(这部分写得比较早,事实上后面出的所有错都会报这个hiprofiler)

[OHOS ERROR] [LOAD] Code:        0000
[OHOS ERROR] [LOAD]
[OHOS ERROR] [LOAD] Reason:      find component hiprofiler failed, please check it in /mnt/f/openharmony_source/out/preloader/rk3568/parts.json.
[OHOS ERROR] [LOAD]
[OHOS ERROR] [LOAD] Error Type:  UNKNOWN ERROR TYPE
[OHOS ERROR] [LOAD]
[OHOS ERROR] [LOAD] Description: NO DESCRIPTION
[OHOS ERROR] [LOAD]
[OHOS ERROR] [LOAD] Solution:    NO SOLUTION
[OHOS ERROR] [LOAD]

TypeScript缺失或版本问题

本人先后遇到了因为缺失TypeScript依赖和TypeScript版本不符缺失必要API的问题,这里将错误内容分别列出,解决方法直接一步到位。
在遇到TypeScript相关问题时,你很可能遇到类似TypeError: ts.isStructDeclaration is not a function的报错,很显然这是因为ts类中并无该方法定义,并且切换版本没有效果。实际上这是因为需要使用根目录下的third_party/typescript这一官方拓展的TypeScript版本。
注:在后续的具体编译过程中需要用到tsc命令,所以如果你没有下载TypeScript可能依然需要运行npm install -g typescript下载,而不能只是使用third_party/typescript(这一段存疑,事实上应该在需要tsc的组件中单独下载而不是全局下载,全局下载会因为缺少拓展api而再次出错;但由于我记录有一点问题,相关的处理暂时缺失,之后如果能确定再补充)

错误内容

缺失TypeScript依赖:

[OHOS ERROR] [GN] ERROR at //build/ohos/sdk/BUILD.gn:79:3: Script returned non-zero exit code.

[OHOS ERROR] [GN]   exec_script(arkts_sdk_config_parser, arkts_sdk_args)

[OHOS ERROR] [GN]   ^----------

[OHOS ERROR] [GN] Current dir: /mnt/f/openharmony_source/out/sdk/

[OHOS ERROR] [GN] Command: /usr/bin/env /mnt/f/openharmony_source/build/ohos/sdk/parse_interface_sdk.py --sdk-description-file ohos_sdk_description_hap.json --root-build-dir ../../ --node-js ../../prebuilts/build-tools/common/nodejs/current/bin/node --output-arkts-sdk-desc-file sdk-interface/ohos_sdk_pub_description_std.json --sdk-build-public false --sdk-build-arkts false --npm-path ../../prebuilts/build-tools/common/nodejs/current/bin/npm --output-interface-sdk sdk-interface

[OHOS ERROR] [GN] Returned 1.

[OHOS ERROR] [GN] stderr:

[OHOS ERROR] [GN]

[OHOS ERROR] [GN] internal/modules/cjs/loader.js:905

[OHOS ERROR] [GN]   throw err;

[OHOS ERROR] [GN]   ^

[OHOS ERROR] [GN]

[OHOS ERROR] [GN] Error: Cannot find module 'typescript'

[OHOS ERROR] [GN] Require stack:

[OHOS ERROR] [GN] - /mnt/f/openharmony_source/interface/sdk-js/build-tools/handleApiFiles.js

[OHOS ERROR] [GN]     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)

[OHOS ERROR] [GN]     at Function.Module._load (internal/modules/cjs/loader.js:746:27)

[OHOS ERROR] [GN]     at Module.require (internal/modules/cjs/loader.js:974:19)

[OHOS ERROR] [GN]     at require (internal/modules/cjs/helpers.js:101:18)

[OHOS ERROR] [GN]     at Object.<anonymous> (/mnt/f/openharmony_source/interface/sdk-js/build-tools/handleApiFiles.js:18:12)

[OHOS ERROR] [GN]     at Module._compile (internal/modules/cjs/loader.js:1085:14)

[OHOS ERROR] [GN]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)

[OHOS ERROR] [GN]     at Module.load (internal/modules/cjs/loader.js:950:32)

[OHOS ERROR] [GN]     at Function.Module._load (internal/modules/cjs/loader.js:790:12)

[OHOS ERROR] [GN]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) {

[OHOS ERROR] [GN]   code: 'MODULE_NOT_FOUND',

[OHOS ERROR] [GN]   requireStack: [

[OHOS ERROR] [GN]     '/mnt/f/openharmony_source/interface/sdk-js/build-tools/handleApiFiles.js'

[OHOS ERROR] [GN]   ]

[OHOS ERROR] [GN] }

[OHOS ERROR] [GN] internal/modules/cjs/loader.js:905

[OHOS ERROR] [GN]   throw err;

[OHOS ERROR] [GN]   ^

[OHOS ERROR] [GN]

[OHOS ERROR] [GN] Error: Cannot find module 'typescript'

[OHOS ERROR] [GN] Require stack:

[OHOS ERROR] [GN] - /mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js

[OHOS ERROR] [GN]     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)

[OHOS ERROR] [GN]     at Function.Module._load (internal/modules/cjs/loader.js:746:27)

[OHOS ERROR] [GN]     at Module.require (internal/modules/cjs/loader.js:974:19)

[OHOS ERROR] [GN]     at require (internal/modules/cjs/helpers.js:101:18)

[OHOS ERROR] [GN]     at Object.<anonymous> (/mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js:16:12)

[OHOS ERROR] [GN]     at Module._compile (internal/modules/cjs/loader.js:1085:14)

[OHOS ERROR] [GN]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)

[OHOS ERROR] [GN]     at Module.load (internal/modules/cjs/loader.js:950:32)

[OHOS ERROR] [GN]     at Function.Module._load (internal/modules/cjs/loader.js:790:12)

[OHOS ERROR] [GN]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) {

[OHOS ERROR] [GN]   code: 'MODULE_NOT_FOUND',

[OHOS ERROR] [GN]   requireStack: [

[OHOS ERROR] [GN]     '/mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js'

[OHOS ERROR] [GN] Traceback (most recent call last):
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR] [GN]     return func(*args, **kwargs)
[OHOS ERROR] [GN]            ^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/services/gn.py", line 133, in _execute_gn_gen_cmd
[OHOS ERROR] [GN]     SystemUtil.exec_command(gn_gen_cmd, self.config.log_path)
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/util/system_util.py", line 137, in exec_command
[OHOS ERROR] [GN]     LogUtil.get_failed_log(log_path, cmd)
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/util/log_util.py", line 219, in get_failed_log
[OHOS ERROR] [GN]     LogUtil.get_gn_failed_log(log_path)
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/util/log_util.py", line 153, in get_gn_failed_log
[OHOS ERROR] [GN]     raise OHOSException(
[OHOS ERROR] [GN] exceptions.ohos_exception.OHOSException: GN Failed! Please check error in /mnt/f/openharmony_source/out/sdk/error.log, and for more build information in /mnt/f/openharmony_source/out/sdk/build.log
[OHOS ERROR] [GN]

[OHOS ERROR] [GN] Code:        3000
[OHOS ERROR] [GN]
[OHOS ERROR] [GN] Reason:      GN Failed! Please check error in /mnt/f/openharmony_source/out/sdk/error.log, and for more build information in /mnt/f/openharmony_source/out/sdk/build.log
[OHOS ERROR] [GN]
[OHOS ERROR] [GN] Error Type:  UNKNOWN
[OHOS ERROR] [GN]
[OHOS ERROR] [GN] Description: An unknown error occurred while executing 'gn gen'.
[OHOS ERROR] [GN]
[OHOS ERROR] [GN] Solution:    There is no solution available. You can check the 'gn_error.log' in the output directory for more information
[OHOS ERROR] [GN]

缺少某ts方法定义:

[OHOS ERROR] [GN] command failed: "/mnt/f/openharmony_source/prebuilts/build-tools/linux-x86/bin/gn gen --json=gn_log.json --args=product_name="ohos-sdk" product_path="/mnt/f/openharmony_source/productdefine/common/products" product_config_path="/mnt/f/openharmony_source/productdefine/common/products" device_name="sdk" device_path="/mnt/f/openharmony_source/device/board/ohos/sdk" device_company="ohos" device_config_path="/mnt/f/openharmony_source/device/board/ohos/sdk" target_cpu="arm64" precise_branch="" is_standard_system=true ohos_build_compiler_specified="" ohos_build_time=1766189037089 ohos_build_datetime="2025-12-20 16:03:57" ace_engine_feature_enable_upgrade_skia=true os_account_multiple_active_accounts=false updater_feature_use_ptable=false updater_feature_updater_gen_executable=true updater_feature_sign_on_server=false graphic_2d_feature_upgrade_skia=true image_framework_feature_upgrade_skia=true qrcodegen_feature_ace_engine_qrcode_able=true skia_feature_upgrade=true mesa3d_feature_upgrade_skia=true build_ohos_sdk=true build_ohos_ndk=true enable_enhanced_opt=false ohos_build_enable_ccache=true ohos_build_type="debug" device_type="default" build_variant="root" skip_generate_module_list_file=true sdk_platform="linux" ndk_platform="linux" use_cfi=false use_thin_lto=false enable_lto_O0=true sdk_check_flag=false enable_ndk_doxygen=false archive_ndk=false sdk_for_hap_build=true enable_archive_sdk=false enable_notice_collection=false enable_process_notice=false root_perf_main="main" runtime_mode="release" /mnt/f/openharmony_source/out/sdk" , ret_code: 1

[OHOS ERROR] [GN] ERROR at //build/ohos/sdk/BUILD.gn:79:3: Script returned non-zero exit code.

[OHOS ERROR] [GN]   exec_script(arkts_sdk_config_parser, arkts_sdk_args)

[OHOS ERROR] [GN]   ^----------

[OHOS ERROR] [GN] Current dir: /mnt/f/openharmony_source/out/sdk/

[OHOS ERROR] [GN] Command: /usr/bin/env /mnt/f/openharmony_source/build/ohos/sdk/parse_interface_sdk.py --sdk-description-file ohos_sdk_description_hap.json --root-build-dir ../../ --node-js ../../prebuilts/build-tools/common/nodejs/current/bin/node --output-arkts-sdk-desc-file sdk-interface/ohos_sdk_pub_description_std.json --sdk-build-public false --sdk-build-arkts false --npm-path ../../prebuilts/build-tools/common/nodejs/current/bin/npm --output-interface-sdk sdk-interface

[OHOS ERROR] [GN] Returned 1.

[OHOS ERROR] [GN] stderr:

[OHOS ERROR] [GN]

[OHOS ERROR] [GN] /mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:128018

[OHOS ERROR] [GN]       throw e;

[OHOS ERROR] [GN]       ^

[OHOS ERROR] [GN]

[OHOS ERROR] [GN] TypeError: ts.isStructDeclaration is not a function

[OHOS ERROR] [GN]     at processAllNodes (/mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js:461:12)

[OHOS ERROR] [GN]     at visitArrayWorker (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:95146:49)

[OHOS ERROR] [GN]     at visitNodes2 (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:95117:19)

[OHOS ERROR] [GN]     at visitLexicalEnvironment (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:95173:16)

[OHOS ERROR] [GN]     at visitEachChildOfSourceFile (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:96351:7)

[OHOS ERROR] [GN]     at Object.visitEachChild (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:95332:33)

[OHOS ERROR] [GN]     at processVisitEachChild1 (/mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js:456:13)

[OHOS ERROR] [GN]     at /mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js:168:14

[OHOS ERROR] [GN]     at transformSourceFileOrBundle (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:96931:49)

[OHOS ERROR] [GN]     at transformation (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:120301:14)

[OHOS ERROR] [GN] /mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:128018

[OHOS ERROR] [GN]       throw e;

[OHOS ERROR] [GN]       ^

[OHOS ERROR] [GN]

[OHOS ERROR] [GN] TypeError: ts.isStructDeclaration is not a function

[OHOS ERROR] [GN]     at processAllNodes (/mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js:461:12)

[OHOS ERROR] [GN]     at visitArrayWorker (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:95146:49)

[OHOS ERROR] [GN]     at visitNodes2 (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:95117:19)

[OHOS ERROR] [GN]     at visitLexicalEnvironment (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:95173:16)

[OHOS ERROR] [GN]     at visitEachChildOfSourceFile (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:96351:7)

[OHOS ERROR] [GN]     at Object.visitEachChild (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:95332:33)

[OHOS ERROR] [GN]     at processVisitEachChild1 (/mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js:456:13)

[OHOS ERROR] [GN]     at /mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js:168:14

[OHOS ERROR] [GN]     at transformSourceFileOrBundle (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:96931:49)

[OHOS ERROR] [GN]     at transformation (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:120301:14)

[OHOS ERROR] [GN] /mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:128018

[OHOS ERROR] [GN]       throw e;

[OHOS ERROR] [GN]       ^

[OHOS ERROR] [GN]

[OHOS ERROR] [GN] TypeError: ts.isStructDeclaration is not a function

[OHOS ERROR] [GN]     at processAllNodes (/mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js:461:12)

[OHOS ERROR] [GN]     at visitArrayWorker (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:95146:49)

[OHOS ERROR] [GN]     at visitNodes2 (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:95117:19)

[OHOS ERROR] [GN]     at visitLexicalEnvironment (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:95173:16)

[OHOS ERROR] [GN]     at visitEachChildOfSourceFile (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:96351:7)

[OHOS ERROR] [GN]     at Object.visitEachChild (/mnt/f/openharmony_source/node_modules/typescript/lib/typescript.js:95332:33)

[OHOS ERROR] [GN]     at processVisitEachChild1 (/mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js:456:13)

[OHOS ERROR] [GN] Traceback (most recent call last):
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR] [GN]     return func(*args, **kwargs)
[OHOS ERROR] [GN]            ^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/services/gn.py", line 133, in _execute_gn_gen_cmd
[OHOS ERROR] [GN]     SystemUtil.exec_command(gn_gen_cmd, self.config.log_path)
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/util/system_util.py", line 137, in exec_command
[OHOS ERROR] [GN]     LogUtil.get_failed_log(log_path, cmd)
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/util/log_util.py", line 219, in get_failed_log
[OHOS ERROR] [GN]     LogUtil.get_gn_failed_log(log_path)
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/util/log_util.py", line 153, in get_gn_failed_log
[OHOS ERROR] [GN]     raise OHOSException(
[OHOS ERROR] [GN] exceptions.ohos_exception.OHOSException: GN Failed! Please check error in /mnt/f/openharmony_source/out/sdk/error.log, and for more build information in /mnt/f/openharmony_source/out/sdk/build.log
[OHOS ERROR] [GN]

[OHOS ERROR] [GN] Code:        3000
[OHOS ERROR] [GN]
[OHOS ERROR] [GN] Reason:      GN Failed! Please check error in /mnt/f/openharmony_source/out/sdk/error.log, and for more build information in /mnt/f/openharmony_source/out/sdk/build.log
[OHOS ERROR] [GN]
[OHOS ERROR] [GN] Error Type:  UNKNOWN
[OHOS ERROR] [GN]
[OHOS ERROR] [GN] Description: An unknown error occurred while executing 'gn gen'.
[OHOS ERROR] [GN]
[OHOS ERROR] [GN] Solution:    There is no solution available. You can check the 'gn_error.log' in the output directory for more information

解决方法

在本人的实践过程中,编译过程不会主动调用到third_party下的TypeScript,设置NODE_PATH也没有效果,所以本人使用了软链接。
移除旧的TypeScript模块(在根目录下运行),如果不移除依然会使用原来的版本:

rm -rf node_modules/typescript

创建符号链接:

# 创建node_modules目录(如果不存在)
mkdir -p node_modules
# 创建链接,指向third_party中的版本
ln -sf $(pwd)/third_party/typescript node_modules/typescript
# 检查符号链接,确定只指向以上文件
ls -la node_modules/typescript

Error: Cannot find module ‘commander’

错误内容

[OHOS ERROR] [GN] ERROR at //build/ohos/sdk/BUILD.gn:79:3: Script returned non-zero exit code.

[OHOS ERROR] [GN]   exec_script(arkts_sdk_config_parser, arkts_sdk_args)

[OHOS ERROR] [GN]   ^----------

[OHOS ERROR] [GN] Current dir: /mnt/f/openharmony_source/out/sdk/

[OHOS ERROR] [GN] Command: /usr/bin/env /mnt/f/openharmony_source/build/ohos/sdk/parse_interface_sdk.py --sdk-description-file ohos_sdk_description_hap.json --root-build-dir ../../ --node-js ../../prebuilts/build-tools/common/nodejs/current/bin/node --output-arkts-sdk-desc-file sdk-interface/ohos_sdk_pub_description_std.json --sdk-build-public false --sdk-build-arkts false --npm-path ../../prebuilts/build-tools/common/nodejs/current/bin/npm --output-interface-sdk sdk-interface

[OHOS ERROR] [GN] Returned 1.

[OHOS ERROR] [GN] stderr:

[OHOS ERROR] [GN]

[OHOS ERROR] [GN] internal/modules/cjs/loader.js:905

[OHOS ERROR] [GN]   throw err;

[OHOS ERROR] [GN]   ^

[OHOS ERROR] [GN]

[OHOS ERROR] [GN] Error: Cannot find module 'commander'

[OHOS ERROR] [GN] Require stack:

[OHOS ERROR] [GN] - /mnt/f/openharmony_source/interface/sdk-js/build-tools/handleApiFiles.js

[OHOS ERROR] [GN]     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)

[OHOS ERROR] [GN]     at Function.Module._load (internal/modules/cjs/loader.js:746:27)

[OHOS ERROR] [GN]     at Module.require (internal/modules/cjs/loader.js:974:19)

[OHOS ERROR] [GN]     at require (internal/modules/cjs/helpers.js:101:18)

[OHOS ERROR] [GN]     at Object.<anonymous> (/mnt/f/openharmony_source/interface/sdk-js/build-tools/handleApiFiles.js:19:19)

[OHOS ERROR] [GN]     at Module._compile (internal/modules/cjs/loader.js:1085:14)

[OHOS ERROR] [GN]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)

[OHOS ERROR] [GN]     at Module.load (internal/modules/cjs/loader.js:950:32)

[OHOS ERROR] [GN]     at Function.Module._load (internal/modules/cjs/loader.js:790:12)

[OHOS ERROR] [GN]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) {

[OHOS ERROR] [GN]   code: 'MODULE_NOT_FOUND',

[OHOS ERROR] [GN]   requireStack: [

[OHOS ERROR] [GN]     '/mnt/f/openharmony_source/interface/sdk-js/build-tools/handleApiFiles.js'

[OHOS ERROR] [GN]   ]

[OHOS ERROR] [GN] }

[OHOS ERROR] [GN] internal/modules/cjs/loader.js:905

[OHOS ERROR] [GN]   throw err;

[OHOS ERROR] [GN]   ^

[OHOS ERROR] [GN]

[OHOS ERROR] [GN] Error: Cannot find module 'commander'

[OHOS ERROR] [GN] Require stack:

[OHOS ERROR] [GN] - /mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js

[OHOS ERROR] [GN]     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)

[OHOS ERROR] [GN]     at Function.Module._load (internal/modules/cjs/loader.js:746:27)

[OHOS ERROR] [GN]     at Module.require (internal/modules/cjs/loader.js:974:19)

[OHOS ERROR] [GN]     at require (internal/modules/cjs/helpers.js:101:18)

[OHOS ERROR] [GN]     at Object.<anonymous> (/mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js:19:19)

[OHOS ERROR] [GN]     at Module._compile (internal/modules/cjs/loader.js:1085:14)

[OHOS ERROR] [GN]     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)

[OHOS ERROR] [GN]     at Module.load (internal/modules/cjs/loader.js:950:32)

[OHOS ERROR] [GN]     at Function.Module._load (internal/modules/cjs/loader.js:790:12)

[OHOS ERROR] [GN]     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) {

[OHOS ERROR] [GN]   code: 'MODULE_NOT_FOUND',

[OHOS ERROR] [GN]   requireStack: [

[OHOS ERROR] [GN]     '/mnt/f/openharmony_source/interface/sdk-js/build-tools/intToNumber.js'

[OHOS ERROR] [GN] Traceback (most recent call last):
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR] [GN]     return func(*args, **kwargs)
[OHOS ERROR] [GN]            ^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/services/gn.py", line 133, in _execute_gn_gen_cmd
[OHOS ERROR] [GN]     SystemUtil.exec_command(gn_gen_cmd, self.config.log_path)
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/util/system_util.py", line 137, in exec_command
[OHOS ERROR] [GN]     LogUtil.get_failed_log(log_path, cmd)
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/util/log_util.py", line 219, in get_failed_log
[OHOS ERROR] [GN]     LogUtil.get_gn_failed_log(log_path)
[OHOS ERROR] [GN]   File "/mnt/f/openharmony_source/build/hb/util/log_util.py", line 153, in get_gn_failed_log
[OHOS ERROR] [GN]     raise OHOSException(
[OHOS ERROR] [GN] exceptions.ohos_exception.OHOSException: GN Failed! Please check error in /mnt/f/openharmony_source/out/sdk/error.log, and for more build information in /mnt/f/openharmony_source/out/sdk/build.log
[OHOS ERROR] [GN]

[OHOS ERROR] [GN] Code:        3000
[OHOS ERROR] [GN]
[OHOS ERROR] [GN] Reason:      GN Failed! Please check error in /mnt/f/openharmony_source/out/sdk/error.log, and for more build information in /mnt/f/openharmony_source/out/sdk/build.log
[OHOS ERROR] [GN]
[OHOS ERROR] [GN] Error Type:  UNKNOWN
[OHOS ERROR] [GN]
[OHOS ERROR] [GN] Description: An unknown error occurred while executing 'gn gen'.
[OHOS ERROR] [GN]
[OHOS ERROR] [GN] Solution:    There is no solution available. You can check the 'gn_error.log' in the output directory for more information
[OHOS ERROR] [GN]

解决方法

比较简单,如果没有执行过prebuilts_download.sh建议先执行一下。
不过本人每次运行后都没有该模块,运行以下命令直接安装:

cd interface/sdk-js/build-tools
../../../prebuilts/build-tools/common/nodejs/current/bin/npm init -y
../../../prebuilts/build-tools/common/nodejs/current/bin/npm install commander

ninja: error: ‘…/…/prebuilts/build-tools/common/ts2abc/node_modules’, needed by ‘clang_x64/obj/arkcompiler/ets_frontend/legacy_bin/js_linux/prebuilts/build-tools/common/ts2abc/node_modules’, missing and no known rule to make it

错误内容

本质是模块node_modules缺失,相关问题应该都可以一样解决。

[OHOS INFO] [NINJA] Excuting ninja command: /mnt/f/openharmony_source/prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -C /mnt/f/openharmony_source/out/sdk build_ohos_sdk

[OHOS ERROR] [NINJA] command failed: "/mnt/f/openharmony_source/prebuilts/build-tools/linux-x86/bin/ninja -w dupbuild=warn -C /mnt/f/openharmony_source/out/sdk build_ohos_sdk" , ret_code: 1

[OHOS ERROR] [NINJA] ninja: error: '../../prebuilts/build-tools/common/ts2abc/node_modules', needed by 'clang_x64/obj/arkcompiler/ets_frontend/legacy_bin/js_linux/prebuilts/build-tools/common/ts2abc/node_modules', missing and no known rule to make it

[OHOS INFO]  User Cpu%: 0.0%

[OHOS INFO]  System Cpu%: 0.2%

[OHOS INFO]  Idle CPU%: 99.8%

[OHOS INFO]  Total Memory: 7.6GB

[OHOS INFO]  Free Memory: 6.7GB

[OHOS INFO]  Swap Memory: 2.0GB

[OHOS INFO]  Filesystem: none, Size: 3.8G, Used: 0, Available: 3.8G, Use%: 0%, Mounted on: /usr/lib/modules/5.15.167.4-microsoft-standard-WSL2

[OHOS INFO]  Filesystem: none, Size: 3.8G, Used: 4.0K, Available: 3.8G, Use%: 1%, Mounted on: /mnt/wsl

[OHOS INFO]  Filesystem: drivers, Size: 201G, Used: 186G, Available: 15G, Use%: 93%, Mounted on: /usr/lib/wsl/drivers

[OHOS INFO]  Filesystem: /dev/sdc, Size: 1007G, Used: 17G, Available: 940G, Use%: 2%, Mounted on: /

[OHOS INFO]  Filesystem: none, Size: 3.8G, Used: 116K, Available: 3.8G, Use%: 1%, Mounted on: /mnt/wslg

[OHOS INFO]  Filesystem: none, Size: 3.8G, Used: 0, Available: 3.8G, Use%: 0%, Mounted on: /usr/lib/wsl/lib

[OHOS INFO]  Filesystem: rootfs, Size: 3.8G, Used: 2.4M, Available: 3.8G, Use%: 1%, Mounted on: /init

[OHOS INFO]  Filesystem: none, Size: 3.8G, Used: 900K, Available: 3.8G, Use%: 1%, Mounted on: /run

[OHOS INFO]  Filesystem: none, Size: 3.8G, Used: 0, Available: 3.8G, Use%: 0%, Mounted on: /run/lock

[OHOS INFO]  Filesystem: none, Size: 3.8G, Used: 0, Available: 3.8G, Use%: 0%, Mounted on: /run/shm

[OHOS INFO]  Filesystem: tmpfs, Size: 4.0M, Used: 0, Available: 4.0M, Use%: 0%, Mounted on: /sys/fs/cgroup

[OHOS INFO]  Filesystem: none, Size: 3.8G, Used: 280K, Available: 3.8G, Use%: 1%, Mounted on: /mnt/wslg/versions.txt

[OHOS INFO]  Filesystem: none, Size: 3.8G, Used: 280K, Available: 3.8G, Use%: 1%, Mounted on: /mnt/wslg/doc

[OHOS INFO]  Filesystem: C:\, Size: 201G, Used: 186G, Available: 15G, Use%: 93%, Mounted on: /mnt/c

[OHOS INFO]  Filesystem: D:\, Size: 283G, Used: 230G, Available: 54G, Use%: 82%, Mounted on: /mnt/d

[OHOS INFO]  Filesystem: E:\, Size: 196G, Used: 127G, Available: 69G, Use%: 66%, Mounted on: /mnt/e

[OHOS INFO]  Filesystem: F:\, Size: 274G, Used: 168G, Available: 107G, Use%: 62%, Mounted on: /mnt/f

[OHOS INFO]  Filesystem: tmpfs, Size: 3.8G, Used: 0, Available: 3.8G, Use%: 0%, Mounted on: /run/qemu

[OHOS INFO]  Filesystem: snapfuse, Size: 56M, Used: 56M, Available: 0, Use%: 100%, Mounted on: /snap/core18/2976

[OHOS INFO]  Filesystem: snapfuse, Size: 56M, Used: 56M, Available: 0, Use%: 100%, Mounted on: /snap/core18/2959

[OHOS INFO]  Filesystem: snapfuse, Size: 9.2M, Used: 9.2M, Available: 0, Use%: 100%, Mounted on: /snap/python38/22

[OHOS INFO]  Filesystem: snapfuse, Size: 51M, Used: 51M, Available: 0, Use%: 100%, Mounted on: /snap/snapd/25577

[OHOS ERROR] [NINJA] Traceback (most recent call last):
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR] [NINJA]     return func(*args, **kwargs)
[OHOS ERROR] [NINJA]            ^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/modules/ohos_build_module.py", line 70, in run
[OHOS ERROR] [NINJA]     raise exception
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/modules/ohos_build_module.py", line 67, in run
[OHOS ERROR] [NINJA]     super().run()
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/modules/interface/build_module_interface.py", line 70, in run
[OHOS ERROR] [NINJA]     raise exception
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/modules/interface/build_module_interface.py", line 68, in run
[OHOS ERROR] [NINJA]     self._ninja()
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/util/timer_util.py", line 30, in inner
[OHOS ERROR] [NINJA]     res = func(*arg, **kwarg)
[OHOS ERROR] [NINJA]           ^^^^^^^^^^^^^^^^^^^
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/modules/interface/build_module_interface.py", line 125, in _ninja
[OHOS ERROR] [NINJA]     self._target_compilation()
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/modules/ohos_build_module.py", line 112, in _target_compilation
[OHOS ERROR] [NINJA]     self.target_compiler.run()
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/services/ninja.py", line 39, in run
[OHOS ERROR] [NINJA]     self._execute_ninja_cmd()
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/services/ninja.py", line 70, in _execute_ninja_cmd
[OHOS ERROR] [NINJA]     SystemUtil.exec_command(
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/util/system_util.py", line 137, in exec_command
[OHOS ERROR] [NINJA]     LogUtil.get_failed_log(log_path, cmd)
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/util/log_util.py", line 220, in get_failed_log
[OHOS ERROR] [NINJA]     LogUtil.get_ninja_failed_log(log_path)
[OHOS ERROR] [NINJA]   File "/mnt/f/openharmony_source/build/hb/util/log_util.py", line 173, in get_ninja_failed_log
[OHOS ERROR] [NINJA]     raise OHOSException(
[OHOS ERROR] [NINJA] exceptions.ohos_exception.OHOSException: NINJA Failed! Please check error in /mnt/f/openharmony_source/out/sdk/error.log, and for more build information in /mnt/f/openharmony_source/out/sdk/build.log
[OHOS ERROR] [NINJA]

[OHOS ERROR] [NINJA] Code:        4016
[OHOS ERROR] [NINJA]
[OHOS ERROR] [NINJA] Reason:      NINJA Failed! Please check error in /mnt/f/openharmony_source/out/sdk/error.log, and for more build information in /mnt/f/openharmony_source/out/sdk/build.log
[OHOS ERROR] [NINJA]
[OHOS ERROR] [NINJA] Error Type:  ninja build error: missing and no known rule to make it
[OHOS ERROR] [NINJA]
[OHOS ERROR] [NINJA] Description: Ninja build error. The ninja build system cannot find the target.
[OHOS ERROR] [NINJA]
[OHOS ERROR] [NINJA] Solution:    Please check the target file is exists.

[OHOS ERROR] [LOAD] Traceback (most recent call last):
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR] [LOAD]     return func(*args, **kwargs)
[OHOS ERROR] [LOAD]            ^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/modules/ohos_build_module.py", line 67, in run
[OHOS ERROR] [LOAD]     super().run()
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/modules/interface/build_module_interface.py", line 66, in run
[OHOS ERROR] [LOAD]     self._load()
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/modules/ohos_build_module.py", line 89, in _load
[OHOS ERROR] [LOAD]     self.loader.run()
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/services/interface/load_interface.py", line 50, in run
[OHOS ERROR] [LOAD]     self.__post_init__()
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/services/loader.py", line 126, in __post_init__
[OHOS ERROR] [LOAD]     self.parts_config_info = load_ohos_build.get_parts_info(
[OHOS ERROR] [LOAD]                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/util/loader/load_ohos_build.py", line 956, in get_parts_info
[OHOS ERROR] [LOAD]     _output_parts_info(parts_config_dict,
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/util/loader/load_ohos_build.py", line 774, in _output_parts_info
[OHOS ERROR] [LOAD]     check_subsystem_and_component(parts_info_output_path, skip_partlist_check)
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/util/loader/load_ohos_build.py", line 697, in check_subsystem_and_component
[OHOS ERROR] [LOAD]     compare_subsystem_and_component(subsystem_name, components_name, subsystem_components_whitelist_info,
[OHOS ERROR] [LOAD]   File "/mnt/f/openharmony_source/build/hb/util/loader/load_ohos_build.py", line 663, in compare_subsystem_and_component
[OHOS ERROR] [LOAD]     raise Exception(message)
[OHOS ERROR] [LOAD] Exception: find component hiprofiler failed, please check it in /mnt/f/openharmony_source/out/preloader/rk3568/parts.json.
[OHOS ERROR] [LOAD]

[OHOS ERROR] [LOAD] Code:        0000
[OHOS ERROR] [LOAD]
[OHOS ERROR] [LOAD] Reason:      find component hiprofiler failed, please check it in /mnt/f/openharmony_source/out/preloader/rk3568/parts.json.
[OHOS ERROR] [LOAD]
[OHOS ERROR] [LOAD] Error Type:  UNKNOWN ERROR TYPE
[OHOS ERROR] [LOAD]
[OHOS ERROR] [LOAD] Description: NO DESCRIPTION
[OHOS ERROR] [LOAD]
[OHOS ERROR] [LOAD] Solution:    NO SOLUTION
[OHOS ERROR] [LOAD]
=====build  error=====

解决方法

对于这一情况

是因为ts2abc中的node_modules实际是一个指向/arkcompiler/ets_frontend/legacy_bin/api8/node_modules 的软链接,而api8中的node_modules缺失。
因此发现组件缺失node_modules时,首先确定其是否使用软链接,并找到实际缺失的文件目录,否则使用本目录;确认目录下存在package.json;然后在该目录下运行命令:

if [ -f "package.json" ]; then
    echo "Found package.json, installing dependencies..."
    npm install --registry https://repo.huaweicloud.com/repository/npm/
else
    echo "No package.json found"
fi
缺失模块比较多的情况下

(这部分也写的比较早,而且我也没有机会实践,不确定是不是真的有用。建议prebuilts执行过后看一看能不能提前预防一下,重点是自己补充过模任何模块后都不要再执行这一脚本了,除非你去脚本里把remove node_modules的部分删掉)
该内容正常来说应该在运行prebuilts_download.sh时下载,会出现该错误很可能是下载过程中发现错误。根据个人经验,一般出现错误的不会只有一个模块,建议运行脚本后根据log,单独下载缺失的模块。
注:根据prebuilts_download.sh脚本内容,每一次开始npm下载前会删除所有已有的node_modules,所以如果已经单独修复过某个模块后,最好不要再运行该脚本。
单独下载前可以注意的log信息有两处:

  1. 每个start npm install, please wait.后的remove node_modules语句,与后续语句相对应,确认缺失内容。
  2. 最后一个start npm install, please wait.结束后的/node_modules not exist, skip node_modules copy语句,确定缺失内容。

其他

缺失out/hb_args/buildargs.json

[OHOS ERROR]  Traceback (most recent call last):
[OHOS ERROR]    File "/mnt/f/openharmony_source/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR]      return func(*args, **kwargs)
[OHOS ERROR]             ^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR]    File "/mnt/f/openharmony_source/build/hb/containers/arg.py", line 389, in read_args_file
[OHOS ERROR]      return IoUtil.read_json_file(args_file_path)
[OHOS ERROR]             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR]    File "/mnt/f/openharmony_source/build/hb/util/io_util.py", line 41, in read_json_file
[OHOS ERROR]      raise e
[OHOS ERROR]    File "/mnt/f/openharmony_source/build/hb/util/io_util.py", line 37, in read_json_file
[OHOS ERROR]      data = json.load(input_f)
[OHOS ERROR]             ^^^^^^^^^^^^^^^^^^
[OHOS ERROR]    File "/mnt/f/openharmony_source/prebuilts/python/linux-x86/3.11.4/lib/python3.11/json/__init__.py", line 293, in load
[OHOS ERROR]      return loads(fp.read(),
[OHOS ERROR]             ^^^^^^^^^^^^^^^^
[OHOS ERROR]    File "/mnt/f/openharmony_source/prebuilts/python/linux-x86/3.11.4/lib/python3.11/json/__init__.py", line 346, in loads
[OHOS ERROR]      return _default_decoder.decode(s)
[OHOS ERROR]             ^^^^^^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR]    File "/mnt/f/openharmony_source/prebuilts/python/linux-x86/3.11.4/lib/python3.11/json/decoder.py", line 337, in decode
[OHOS ERROR]      obj, end = self.raw_decode(s, idx=_w(s, 0).end())
[OHOS ERROR]                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR]    File "/mnt/f/openharmony_source/prebuilts/python/linux-x86/3.11.4/lib/python3.11/json/decoder.py", line 355, in raw_decode
[OHOS ERROR]      raise JSONDecodeError("Expecting value", s, err.value) from None
[OHOS ERROR]  json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[OHOS ERROR]

[OHOS ERROR]  Code:        0000
[OHOS ERROR]
[OHOS ERROR]  Reason:      Expecting value: line 1 column 1 (char 0)
[OHOS ERROR]
[OHOS ERROR]  Error Type:  UNKNOWN ERROR TYPE
[OHOS ERROR]
[OHOS ERROR]  Description: NO DESCRIPTION
[OHOS ERROR]
[OHOS ERROR]  Solution:    NO SOLUTION
[OHOS ERROR]
Error reading JSON file /mnt/f/openharmony_source/out/hb_args/buildargs.json
Error reading JSON file /mnt/f/openharmony_source/out/hb_args/buildargs.json

[OHOS ERROR]  Traceback (most recent call last):
[OHOS ERROR]    File "/mnt/f/openharmony_source/build/hb/containers/status.py", line 47, in wrapper
[OHOS ERROR]      return func(*args, **kwargs)
[OHOS ERROR]             ^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR]    File "/mnt/f/openharmony_source/build/hb/containers/arg.py", line 389, in read_args_file
[OHOS ERROR]      return IoUtil.read_json_file(args_file_path)
[OHOS ERROR]             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR]    File "/mnt/f/openharmony_source/build/hb/util/io_util.py", line 41, in read_json_file
[OHOS ERROR]      raise e
[OHOS ERROR]    File "/mnt/f/openharmony_source/build/hb/util/io_util.py", line 37, in read_json_file
[OHOS ERROR]      data = json.load(input_f)
[OHOS ERROR]             ^^^^^^^^^^^^^^^^^^
[OHOS ERROR]    File "/mnt/f/openharmony_source/prebuilts/python/linux-x86/3.11.4/lib/python3.11/json/__init__.py", line 293, in load
[OHOS ERROR]      return loads(fp.read(),
[OHOS ERROR]             ^^^^^^^^^^^^^^^^
[OHOS ERROR]    File "/mnt/f/openharmony_source/prebuilts/python/linux-x86/3.11.4/lib/python3.11/json/__init__.py", line 346, in loads
[OHOS ERROR]      return _default_decoder.decode(s)
[OHOS ERROR]             ^^^^^^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR]    File "/mnt/f/openharmony_source/prebuilts/python/linux-x86/3.11.4/lib/python3.11/json/decoder.py", line 337, in decode
[OHOS ERROR]      obj, end = self.raw_decode(s, idx=_w(s, 0).end())
[OHOS ERROR]                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[OHOS ERROR]    File "/mnt/f/openharmony_source/prebuilts/python/linux-x86/3.11.4/lib/python3.11/json/decoder.py", line 355, in raw_decode
[OHOS ERROR]      raise JSONDecodeError("Expecting value", s, err.value) from None
[OHOS ERROR]  json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[OHOS ERROR]

[OHOS ERROR]  Code:        0000
[OHOS ERROR]
[OHOS ERROR]  Reason:      Expecting value: line 1 column 1 (char 0)
[OHOS ERROR]
[OHOS ERROR]  Error Type:  UNKNOWN ERROR TYPE
[OHOS ERROR]
[OHOS ERROR]  Description: NO DESCRIPTION
[OHOS ERROR]
[OHOS ERROR]  Solution:    NO SOLUTION
[OHOS ERROR]
=====build  error=====

解决方法

推测是因为过早提前终止编译,导致该文件被创建但没有写入内容。
清理后重新开始编译即可:

cd /mnt/f/openharmony_source
rm -rf out/hb_args/ .hb/

附记与致谢

本文是笔者在南京大学本科三年级课程《移动互联网应用开发》中完成的作业结果之一,本文应该是最后一篇。感谢OpenHarmony开源项目提供的学习机会,也感谢课程老师的指导。
因为时间原因有一部分错误内容还没有整理出来,之后有可能会继续更新;如果有遇到相同问题但使用文档中方法无法解决的,欢迎在评论区讨论。
笔者之前写过一篇介绍方舟运行时的文章,不过实际使用下来,这个工具在编译上就会遇到相当多的问题,并且由于项目本身的复杂性,这些问题的处理也比较耗时。根据个人观察,大部分的问题都来源于模块缺失、node_modules等缺失、typescript的版本问题、和大量软链接造成的复杂性。有问题欢迎在评论区指正&讨论。

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐