执行主函数报错,07:22:17.632/E: Error: Module "storage/emulated/0/Hamibot/common/shell_utils.js" not found. (file:/storage/emulated/0/Hamibot/common/common_utils.js#1)
Error: Module "storage/emulated/0/Hamibot/common/shell_utils.js" not found.
at file:/storage/emulated/0/Hamibot/common/common_utils.js:1:0
at file:/storage/emulated/0/Hamibot/executor_new.js:4:0
at _load (file:///android_asset/modules/jvm-npm.js:60:0)
at run (6a27471ecf45649feab57d36.js:75:0)
at 6a27471ecf45649feab57d36.js:44:0
回答
这个报错的根本原因是模块路径解析失败,Hamibot 的 JavaScript 引擎(Rhino)无法在指定位置找到 shell_utils.js。错误信息中的路径 storage/emulated/0/Hamibot/common/shell_utils.js 缺少了开头的 /,导致引擎将其识别为相对路径而非绝对路径,从而查找失败。
你可以按以下步骤快速修复:
1. 检查并修改 common_utils.js 中的引入语句
打开 common_utils.js 第 1 行附近的代码,查看 require 的写法。错误的写法通常类似:
// 文档地址 https://docs.hamibot.com/
var shellUtils = require('storage/emulated/0/Hamibot/common/shell_utils.js');
2. 强烈建议改用相对路径
Hamibot 脚本在不同设备或目录下运行时,绝对路径极易失效。如果 common_utils.js 和 shell_utils.js 位于同一个 common 文件夹内,直接改为相对路径:
// 文档地址 https://docs.hamibot.com/
var shellUtils = require('./shell_utils.js');
如果 common_utils.js 在 common 的上级目录,则改为:
// 文档地址 https://docs.hamibot.com/
var shellUtils = require('./common/shell_utils.js');
3. 如果必须使用绝对路径
确保路径以 / 开头,且文件确实存在:
// 文档地址 https://docs.hamibot.com/
var shellUtils = require('/storage/emulated/0/Hamibot/common/shell_utils.js');
注意:Android 11 及以上系统启用了分区存储,直接读写 /storage/emulated/0/ 可能受权限限制。相对路径是更稳定、更符合 Hamibot 最佳实践的做法。
4. 核对文件名称与大小写
Android 文件系统严格区分大小写。请确认:
- 文件名确实是
shell_utils.js(不是Shell_utils.js或shell-utils.js) - 文件确实存放在你代码指向的目录中
- 文件内容没有语法错误(有时模块本身解析失败也会抛出 not found 类错误)
修改 require 路径后,重新运行主函数即可。如果调整后仍报错,请提供 common_utils.js 中 require 的具体代码以及两个文件的实际存放目录结构,我会帮你进一步定位。