bug: Not compatible with bun runtime
Majoramari opened this issue · 5 comments
Is there an existing issue for this?
- I have searched the existing issues
Description of the bug
For some reason I a lot of errors like this
Error when loading 'undefined/CorePrefixedMessage.js':
Error when loading 'undefined/CorePreMessageParser.js':
// etc...
this is my index.ts and I have a ping.ts
import { SapphireClient } from "@sapphire/framework";
import { GatewayIntentBits } from "discord.js";
const client = new SapphireClient({
intents: [
GatewayIntentBits.MessageContent,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
],
loadMessageCommandListeners: true,
});
client.login("MY_TOKEN");
Steps To Reproduce
just follow the instructions until here
Expected behavior
The bot should start
Screenshots
Additional context
Bun 1.0.3
Taking messages from @vladfrangu on Discord:
The more complete answer is yes but also no
There's a missing field on the return type of fs.promises.opendir which causes issues with loading pieces. Outside of that, your custom pieces will load! but there's another weird issue with sapphires preincluded pieces and bun not recognizing the exports.
Once those things are solved, I mean...they advertise drop in replacement
I plan on opening these issues to bun, and seeing if I could even PR a fix for the fs stuff
Idk if he already created said issues
Hi! I want to propose a possible workaround for this (while using Bun):
Register your pieces as virtual: this requires a lot of manual work, but it's possible since @sapphire/pieces@3.9.0
and @sapphire/framework@4.8.0
. Simply import each of your modules manually and call container.stores.loadPiece
. Guides for this will come out soon. :)
In the near future, I'd like to move Store#walk
to the ILoaderStrategy
(and implement it in LoaderStrategy
), this way you'd be able to use runtime-specific APIs instead of Node.js's with a custom strategy.
I've actually been using a heavily modified version of Sapphire/Pieces for a while now, with bun support. I did a little trickery by using glob instead of fs which resolved these issues, however I completely gutted features like categories, so it may break other use cases. Investigate at your own risk.
Additionally, as of oven-sh/bun#7292, fs.promises.opendir
has been fixed and will most likely be available in the next release.
Also, to help the Sapphire devs with the headache that is bun, you can use Reflect.has(process, "isBun")
in the LoaderStrategy constructor to see if the process is running on bun. Further more, using that condition you can bypass doing the mjs import check and replace require(<whatever>)
with import(<whatever>)
since bun does all the work on the backend.
@Zendrex as per the comment of @kyranet above yours Bun support has already been added. The issue was kept open for @Majoramari to acknowledge and reply but seeing as that seems to cause confusion I am going to close this.
I can confirm its working now I just didn't have the time to try it out!