Errors loading Commands and Listeners on bun run

When trying to run application via bun run, receive errors for each command and listener created. Here the following error:
Error when loading '/home/thrump/projects/botc/src/commands/createChannel.ts': 9 | LoaderErrorType2["UnknownStore"] = "UNKNOWN_STORE";
10 | return LoaderErrorType2;
11 | })(LoaderErrorType || {});
12 | var _LoaderError = class _LoaderError extends Error {
13 | constructor(type, message) {
14 | super(message);
^
error: A compatible class export was not found. [/home/thrump/projects/botc/src/commands/createChannel.ts]
path: "/home/thrump/projects/botc/src/commands/createChannel.ts"
at new LoaderError (/home/thrump/projects/botc/node_modules/.deno/@[email protected]/node_modules/@sapphire/pieces/dist/esm/lib/errors/LoaderError.mjs:14:5)
at new MissingExportsError (/home/thrump/projects/botc/node_modules/.deno/@[email protected]/node_modules/@sapphire/pieces/dist/esm/lib/errors/MissingExportsError.mjs:6:5)
at /home/thrump/projects/botc/node_modules/.deno/@[email protected]/node_modules/@sapphire/pieces/dist/esm/lib/strategies/LoaderStrategy.mjs:57:13
Error when loading '/home/thrump/projects/botc/src/commands/createChannel.ts': 9 | LoaderErrorType2["UnknownStore"] = "UNKNOWN_STORE";
10 | return LoaderErrorType2;
11 | })(LoaderErrorType || {});
12 | var _LoaderError = class _LoaderError extends Error {
13 | constructor(type, message) {
14 | super(message);
^
error: A compatible class export was not found. [/home/thrump/projects/botc/src/commands/createChannel.ts]
path: "/home/thrump/projects/botc/src/commands/createChannel.ts"
at new LoaderError (/home/thrump/projects/botc/node_modules/.deno/@[email protected]/node_modules/@sapphire/pieces/dist/esm/lib/errors/LoaderError.mjs:14:5)
at new MissingExportsError (/home/thrump/projects/botc/node_modules/.deno/@[email protected]/node_modules/@sapphire/pieces/dist/esm/lib/errors/MissingExportsError.mjs:6:5)
at /home/thrump/projects/botc/node_modules/.deno/@[email protected]/node_modules/@sapphire/pieces/dist/esm/lib/strategies/LoaderStrategy.mjs:57:13
Here is an example of a file (very barebone):
import { isMessageInstance } from "@sapphire/discord.js-utilities";
import { Command } from "@sapphire/framework";

export class CreateChannelsCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, { ...options });
}

public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName("createChannels")
.setDescription("Will create individual channels for each player")
);
}

public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
console.log("test");
}
}
import { isMessageInstance } from "@sapphire/discord.js-utilities";
import { Command } from "@sapphire/framework";

export class CreateChannelsCommand extends Command {
public constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, { ...options });
}

public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName("createChannels")
.setDescription("Will create individual channels for each player")
);
}

public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
console.log("test");
}
}
Solution:
i see the issue now: the documentation mentions to set your "main" in the package.json to the src/index.js, so in my head i assumed it needed to point to my src/index.ts. but i guess based off the outDir in the tsConfig, have to point to dist/index.js...
Jump to solution
8 Replies
Favna
Favna5mo ago
What's your tsconfig? Also are you sure you're using bun and not Deno because the error has node_modules/.deno
☆彡
☆彡OP5mo ago
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
@Boomeravna , sorry i was also testing to see if it was a bun runetime compiler/runetime issue so tried it with Deno but they both gave the same error decided to also give other configurations of the tsconfig.json, so tried this as well:
"compilerOptions": {
"lib": ["es2023"],
"module": "node16",
"target": "es2022",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node16"
}
"compilerOptions": {
"lib": ["es2023"],
"module": "node16",
"target": "es2022",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node16"
}
same error
Favna
Favna5mo ago
That seems fine at a glance. Make sure to nuke your node_modules between Deno and Bun tries. And for bun you can compare with https://github.com/sapphiredev/node-bun-example which is a known working sample.
GitHub
GitHub - sapphiredev/node-bun-example: A bot starting point with bu...
A bot starting point with bun for dev and node for prod - sapphiredev/node-bun-example
☆彡
☆彡OP5mo ago
Sure, I'll try taking a look at this and nuke my node modules. One thing I did notice before my power went out, the file that's loading in the files, there was a check to see if it the file was a ts file and if it's an ESMmodule export and that ESMmodule was false So something related to esm module In the @sapphire/pieces
Favna
Favna5mo ago
Setting "type": "module" in the package.json ensures sapphire loads in ESM mode
☆彡
☆彡OP5mo ago
hmm, so i did update my package.json to type:"module" now and i can see that this.clientUsesESModules now returns true, so it grabs the url and appends the searchParams. so it looks like this:
URL {
href: "file:///home/thrump/projects/botc/src/commands/unmute.ts?d=1721576525813&name=unmute&extension=.ts",
origin: "null",
protocol: "file:",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "/home/thrump/projects/botc/src/commands/unmute.ts",
hash: "",
search: "?d=1721576525813&name=unmute&extension=.ts",
searchParams: URLSearchParams {
"d": "1721576525813",
"name": "unmute",
"extension": ".ts",
},
toJSON: [Function: toJSON],
toString: [Function: toString],
}
URL {
href: "file:///home/thrump/projects/botc/src/commands/unmute.ts?d=1721576525813&name=unmute&extension=.ts",
origin: "null",
protocol: "file:",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "/home/thrump/projects/botc/src/commands/unmute.ts",
hash: "",
search: "?d=1721576525813&name=unmute&extension=.ts",
searchParams: URLSearchParams {
"d": "1721576525813",
"name": "unmute",
"extension": ".ts",
},
toJSON: [Function: toJSON],
toString: [Function: toString],
}
but i guess the return mjsImport(url) returns back an empty object i guess ill try to look more in the example one, but the example one seems a bit weird, cause you essentially serve the bun.ts who then imports the main.ts to run is there a particular reason for that approach
Solution
☆彡
☆彡5mo ago
i see the issue now: the documentation mentions to set your "main" in the package.json to the src/index.js, so in my head i assumed it needed to point to my src/index.ts. but i guess based off the outDir in the tsConfig, have to point to dist/index.js
☆彡
☆彡OP5mo ago
so now errors dont throw. though it seems my slash commands or listeners aren't still registered. for the example above, i put in the event for voiceStateUpdate, and tested just joining a VC to see a console.log be fired, but didn't seem like anything got fired
Want results from more Discord servers?
Add your server