当前位置: 首页 > news >正文

在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

不能用中文目录

http://www.lryc.cn/news/604368.html

相关文章:

  • 【编号65】广西地理基础数据(道路、水系、四级行政边界、地级城市、DEM等)
  • 在 Elasticsearch 8.19 和 9.1 中引入更强大、更具弹性和可观测性的 ES|QL
  • Buck的Loadline和DVS区别和联系
  • Jenkinsfile 报错
  • 一篇讲清Redis中常见数据类型的用法
  • Three.js 与 WebXR:初识 VR/AR 开发
  • 国产化再进一步,杰和科技推出搭载国产芯片的主板
  • LoRaWAN协议,提升公用事业能源效率的“隐形引擎”
  • Ubuntu22.04.1搭建php运行环境
  • C++ 高性能容器:ankerl::unordered_dense::map
  • 元码智能“大眼睛”机器人首发,智启生活新纪元!
  • RabbitMQ 发送方确认的两大工具 (With Spring Boot)
  • Metering Solution for Solar + Storage光伏+储能计量解决方案 UL 2735 Certification功率表能源监测电表
  • 第2章 cmd命令基础:常用基础命令(2)
  • c++之基础B之sort排序(第三个参数没有)(第二课)
  • 在macOS上使用VS Code和Clang配置C++开发环境
  • 湖北大学暑期实训优秀作品:面向美丽中国的数据化可视平台
  • 涉及实验(随机分组)的一些概念
  • 【swoole Windows 开发(swoole-cli 开发 hyperf)】
  • 时间序列预测的自回归方法
  • Product Hunt 每日热榜 | 2025-07-30
  • tplink er2260t配置带vlan的pppoe拨号
  • Java学习第八十九部分——“层”(续)
  • 学会使用golang zap日志库
  • 【动态规划算法】斐波那契数列模型
  • 嵌入式开发学习———Linux环境下数据结构学习(五)
  • 服务器与电脑主机的区别,普通电脑可以当作服务器用吗?
  • 从结构到交互:HTML5进阶开发全解析——语义化标签、Canvas绘图与表单设计实战
  • MCP提示词工程:上下文注入的艺术与科学
  • 【机器学习11】“分类算法“评估矩阵:从对数损失、AUC和ROC、混淆矩阵与分类报告等角度来评估算法