在Trae中使用MoonBit月兔
在MoonBit月兔手册中MoonBit:新手之旅 — MoonBit 月兔 v0.6.22 文档,讲到在VSCode中安装MoonBit月兔插件。于是想到Trae也是VSCode内核,那么在Trae中应该也可以使用MoonBit月兔。
首先启动Trae,发现7.25日升级到2.0.4版本,主要是增加了新模型 Kimi-K2 和 Qwen3-Coder,真是太棒了!但是发现
首先在Trae的插件市场搜索MoonBit,看到有MoonBit 和MoonBit nightly ,先安装普通版吧
安装之后,并没有像roo 、cline等插件那样出现一个插件图标。
让Trae写个demo试试:请帮我用moonbit写一个hello world、
它创建了一个目录,然后提示到目录里执行moon run。可以看到moonbit的代码有高亮提示,证明插件安装成功。
moon run的时候提示需要安装工具链。
安装工具链
在MoonBit中安装工具链moonbit toolchain
在VSCode或Trae中安装:
在搜索栏里,输入>moonbit:
选择:Install moonbit toolchain
感觉这里很不稳定,有时候能出来Install moonbit toolchain ,有时候不出来。
出来Install moonbit toolchain之后,点击,有时候能出来moonbit的配置选项,有时候不出来....
大约是Trae的问题。
在VSCode里面,选择Install moonbit toolchain之后,出现moonbit toolchain的安装提示,经确认后会自动安装。原来这里调用了这句命令:
shell,irm https://cli.moonbitlang.cn/install/powershell.ps1 | iex,
安装的东西挺多,还需要编译,需要一段时间
耗时相当长,反正比安装VSCode或者Clang等时间要长。
安装完毕,重启VSCode,就可以使用moon命令啦!
moon
The build system and package manager for MoonBit.Usage: moon [OPTIONS] <COMMAND>Commands:new Create a new MoonBit modulebuild Build the current packagecheck Check the current package, but don't build object filesrun Run a main packagetest Test the current packageclean Remove the target directoryfmt Format source codedoc Generate documentationinfo Generate public interface (`.mbti`) files for all packages in the modulebench Run benchmarks in the current packageadd Add a dependencyremove Remove a dependencyinstall Install dependenciestree Display the dependency treelogin Log in to your accountregister Register an account at mooncakes.iopublish Publish the current module
在powershell中用命令安装
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser; irm https://cli.moonbitlang.com/install/powershell.ps1 | iex
我没明白为什么还要再装一下,那moonbit插件是做什么用的?哦,明白了,如果没有自动安装,就用这条命令手动安装,比如Trae里面。
执行demo例子
让Trae生成了一个moonbit的demo,
感觉moonbit真的太复杂了,一个hello world包换了老多文件
主程序main.mbt很简单:
fn main {println("Hello, MoonBit!")
}
但是需要其它文件配合:
E:\moonbit_test>dir驱动器 E 中的卷是 新加卷卷的序列号是 CA89-671DE:\moonbit_test 的目录2025/07/30 23:28 <DIR> .
2025/07/30 23:28 <DIR> ..
2025/07/30 23:28 <DIR> .mooncakes
2025/07/30 23:28 40 main.mbt
2025/07/30 23:28 188 moon.mod.json
2025/07/30 23:28 104 moon.pkg.json
2025/07/30 23:28 <DIR> target3 个文件 332 字节4 个目录 14,125,985,792 可用字节E:\moonbit_test>tree
卷 新加卷 的文件夹 PATH 列表
卷序列号为 CA89-671D
E:.
├─.mooncakes
└─target└─wasm-gc└─release└─build
执行结果:
moon run main.mbt
Hello, MoonBit!
搞定,收工!
调试
moon run报错Check the spelling of the name
moon run
moon: The term 'moon' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
用moon run main.mbt
moon run main.mbt报错error: `` is not a main package
moon run main.mbt
error: `` is not a main package
不知道咋回事,给Trae,让它去修改了。
moon run main.mbt报错Error: Sys_error("E:\\work\\\231\128\155\239\184\191\231\175\132360\\hello_moonbit\\main.mbt: No such file or directory")
moon run main.mbt
failed: moonc build-package -error-format json E:\work\学习360\hello_moonbit\main.mbt -o E:\work\学习360\hello_moonbit\target\wasm-gc\release\build\hello_moonbit.core -pkg hello_moonbit -is-main -std-path C:\Users\Admin\.moon\lib\core\target\wasm-gc\release\bundle -pkg-sources hello_moonbit:E:\work\学习360\hello_moonbit -target wasm-gc
-- --
/ // / __--------_
/ // /_/ \
--- - \ __
/ X / ____ / )
*_________/__/_____/______/ `--
Oops, the compiler has encountered an unexpected situation.
This is a bug in the compiler.
A bug report containing the error description and relevant code would be
greatly appreciated. You can submit the bug report here:
https://github.com/moonbitlang/moonbit-docs/issues/new?template=ice.md
Error: Sys_error("E:\\work\\\231\128\155\239\184\191\231\175\132360\\hello_moonbit\\main.mbt: No such file or directory")
Compiler args: moonc build-package -error-format json "E:\\work\\瀛︿範360\\hello_moonbit\\main.mbt" -o "E:\\work\\瀛︿ 範360\\hello_moonbit\\target\\wasm-gc\\release\\build\\hello_moonbit.core" -pkg hello_moonbit -is-main -std-path "C:\\Users\\Admin\\.moon\\lib\\core\\target\\wasm-gc\\release\\bundle" -pkg-sources "hello_moonbit:E:\\work\\瀛︿範360\\hello_moonbit" -target wasm-gc
moonc version: v0.6.22
error: failed when building
不能用中文目录