Dev works, prod doesnt

Has anyone experienced commands working in dev, but not prod? The commands just will not be registered
Solution:
try the new version #Announcements
Jump to solution
68 Replies
Dawson
DawsonOP5mo ago
No description
Dawson
DawsonOP5mo ago
I specify a custom directory though with baseUserDirectory: botDirectory, works completely fine in dev
Dawson
DawsonOP5mo ago
LearnSpigot: Send and save code snippets on our pastebin
LearnSpigot provides a free web-based pastebin service for storing and sharing code snippets with anyone. Powered by hastebin.
Dawson
DawsonOP5mo ago
Here's with Trace debug enabled
Dawson
DawsonOP5mo ago
It also does set my bots status
No description
Favna
Favna5mo ago
first thought is that your baseUserDirectory between dev and prod is not the same. Do you compile the src to dist or such? are the file systems identical between the 2? Look into those things
Spinel
Spinel5mo ago
1. Which version of @sapphire/framework are you using? 2. What's your file/folder structure? 3. Did you use the CLI to generate your bot? 4. What's your main (CJS) or module (ESM) property in package.json 5. Are you using TypeScript? And if so, how are you compiling and running your code? That is to say, what are your build and startup scripts? - Did you remove your output folder and rebuild then try again? 6. Is your problem related to message commands? Did you add loadMessageCommandListeners to your SapphireClient options Remember that if you are new to @sapphire/framework it is important that you read the user guide.
Dawson
DawsonOP5mo ago
No, not that I am aware of. The start command runs the TS directly
No description
Dawson
DawsonOP5mo ago
wrong project, here's the correct image
No description
Dawson
DawsonOP5mo ago
1. "@sapphire/framework": "^4.0.0", 3. No, the hyperlink leads to a site with broken links btw 4. main is set to src/index.ts 5. Yes, bun runtime. "start": "bun run src/index.ts", 6. No, in prod it would get wiped 7. Yes, loadMessageCommandListeners: true,
No description
Favna
Favna5mo ago
I think this is the problem, question is, why ... might be best to set some breakpoints or extra logs in the files in node_modules
No description
Dawson
DawsonOP5mo ago
@Samu
Samu
Samu5mo ago
Thanks yeah I have seen this Thanks everyone, will check every answer out ASAP
Dawson
DawsonOP5mo ago
I added a debug message into a command
No description
Dawson
DawsonOP5mo ago
No description
Dawson
DawsonOP5mo ago
it simply does not get called during prod
Favna
Favna5mo ago
Yeah it doesn't get loaded at all Like I showed loading gets skipped So you have to add the log to the code in @sapphire/pieces
Dawson
DawsonOP5mo ago
ah And I assume this needs to be changed in prod
Favna
Favna5mo ago
If you run in docker then you can explore something like patch package. And yeah
Dawson
DawsonOP5mo ago
@Samu 😅
Favna
Favna5mo ago
I'd validate if your log change works in Dev tho
Samu
Samu5mo ago
interesting
Favna
Favna5mo ago
There must be some if check that is failing The question is which and why
Dawson
DawsonOP5mo ago
alright let's see how hard this is gonna be Can we manually register everything in the mean time?
Samu
Samu5mo ago
@Boomeravna Hi, sorry for the ping mate, don't want to disturb you but we need to get this running ASAP, can you help us when you get a chance?
Favna
Favna5mo ago
@Dawson dont think that'll work @Samu not sure in what way I can help other than what I've said, especially not without access to your code.
Samu
Samu5mo ago
Okay, thanks for your time,we've been trying with what you said, thanks for all the feedback! My ping was more meant for Dawson's message, we really appreciate it ❤️
Favna
Favna5mo ago
the reason I dont think it will is because it will use the loaderstrategy regardless anyway im macro crafting in ff14 right now so I got some minutes to click around the code can you start by checking if process.version includes the string 'bun'?
Samu
Samu5mo ago
sure
Favna
Favna5mo ago
other than that I think this is the function where it would get filtered out: https://github.com/sapphiredev/pieces/blob/2c42d6efda2f6711e1ce56ce2a9025c001fcad49/src/lib/strategies/LoaderStrategy.ts#L38-L51 so the file name cannot start with _ (it doesnt) and TS loading has to be enabled which is https://github.com/sapphiredev/pieces/blob/2c42d6efda2f6711e1ce56ce2a9025c001fcad49/src/lib/strategies/env.ts#L35-L73 uh that is of course assuming you are not overwriting the LoaderStrategy from sapphire pieces. That is quite complex to do so I assume you're not.
Samu
Samu5mo ago
We made a patch and used postinstall to run it
Favna
Favna5mo ago
just to add logging or?
Samu
Samu5mo ago
Yeah that's what we are working on
Samu
Samu5mo ago
Mainly yeah, i need to test everything out still
No description
Favna
Favna5mo ago
btw how do you run on prod? docker? pm2? something else? if not docker then I know it'll require extra setup but I can recommend it since you can also run the same docker image locally and you dont need to go to prod all the time, you can replicate the exact environment locally.
Samu
Samu5mo ago
Docker, we use Dokploy
Favna
Favna5mo ago
ah well then if you build the docker image locally and run it then you should be running the same environment locally as you would in prod that should save a lot of time ive never heard of dokploy but I doubt it does anything special and just follows the containerd spec
Samu
Samu5mo ago
Yeah that's an option, fortunately the deployment time is great (about 1min max) so it doesn't take us that much Nope, it doesn't
Favna
Favna5mo ago
hm that's very odd you do run with bun in prod? because that would do it then TS filess arent loaded as per what I linked
Samu
Samu5mo ago
console.log("Running on Bun:", process.version.includes('bun'));
No description
Samu
Samu5mo ago
Yeah Okay, the thing i've tried using JS as well (and oh god the experience is terrible after using TypeScript this whole time xD) but still didn't load
Favna
Favna5mo ago
the only other idea I have is that it would be baseUserDirectory related that you're overwriting. Any particular reason you're overwriting it? also what is process.version then?
Samu
Samu5mo ago
We first did it because we made the commands and listeners folder into a general bot folder (not package), so i thought that was the standard thing to do, as long as i remember we even tried without overwriting it but it's been a while, worth a try- Also since i'm at it, i'll log process.version as well ignore the first part, we already removed it
export const discordClient = new SapphireClient({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildScheduledEvents
],
loadMessageCommandListeners: true,
allowedMentions: {
repliedUser: true,
},
loadApplicationCommandRegistriesStatusListeners: true,
logger: {
level: LogLevel.Trace
},
loadDefaultErrorListeners: true
});
export const discordClient = new SapphireClient({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildScheduledEvents
],
loadMessageCommandListeners: true,
allowedMentions: {
repliedUser: true,
},
loadApplicationCommandRegistriesStatusListeners: true,
logger: {
level: LogLevel.Trace
},
loadDefaultErrorListeners: true
});
Favna
Favna5mo ago
it's not a mono repo structure but the standard is like this: https://github.com/favware/xiveventbuddy/tree/main/src I would recommend in a mono repo you do a similar setup but in a subfolder and just have your devdeps and scripts and such shared. I just this through node but bun would be mostly the same. In https://github.com/favware/xiveventbuddy/blob/main/package.json the difference would only be that whereever it says dist/xiveventbuddy.js would become src/xiveventbuddy.ts
GitHub
xiveventbuddy/src at main · favware/xiveventbuddy
A user friendly first discord bot to host your XIV events - favware/xiveventbuddy
Samu
Samu5mo ago
@workspace/api:start: Running on Bun: false @workspace/api:start: Process Version: v22.6.0
Favna
Favna5mo ago
that looks more like you're running node... ? There is no bun 22.6.0 what are your dockerfile and package.json?
Samu
Samu5mo ago
odd, i didn't set up deployment, @Dawson Sure, Dockerfile:
FROM oven/bun:1-alpine

WORKDIR /app

COPY package.json bun.lock ./
COPY packages ./packages
COPY apps/api/package.json ./apps/api/package.json
COPY apps/api/patches ./patches
RUN bun install
RUN bun patch-package

COPY . .

EXPOSE 3001
CMD ["bun", "run", "start:api"]
FROM oven/bun:1-alpine

WORKDIR /app

COPY package.json bun.lock ./
COPY packages ./packages
COPY apps/api/package.json ./apps/api/package.json
COPY apps/api/patches ./patches
RUN bun install
RUN bun patch-package

COPY . .

EXPOSE 3001
CMD ["bun", "run", "start:api"]
package.json:
{
"name": "@workspace/api",
"module": "src/index.ts",
"main": "src/index.ts",
"type": "module",
"scripts": {
"dev": "bun run --watch src/index.ts",
"start": "bun run src/index.ts",
"email": "email dev --port 3002",
"stripe:listen": "stripe listen --forward-to http://localhost:3001/api/auth/stripe/webhook --events \"checkout.session.completed,customer.subscription.updated,customer.subscription.deleted,payment_intent.succeeded,payment_intent.payment_failed\"",
"postinstall": "patch-package"
},
"devDependencies": {
"@types/bun": "^1.2.13",
"@types/cors": "^2.8.18",
"patch-package": "^8.0.0",
"react-email": "4.0.15",
"typescript": "^5.8.2"
},
"peerDependencies": {
"typescript": "^5"
},
"dependencies": {
"@discordjs/rest": "^2.5.0",
"@elysiajs/cors": "^1.3.3",
"@elysiajs/cron": "^1.3.0",
"@elysiajs/trpc": "^1.1.0",
"@elysiajs/websocket": "^0.2.8",
"@react-email/components": "0.0.41",
"@sapphire/framework": "^4.0.0",
"@t3-oss/env-core": "^0.13.4",
"@trpc/client": "^11.1.2",
"@trpc/server": "^11.1.2",
"@vermaysha/discord-webhook": "^1.4.0",
"@workspace/db": "workspace:*",
"@workspace/logger": "workspace:*",
"better-auth": "^1.2.8",
"cors": "^2.8.5",
"discord-api-types": "^0.38.8",
"discord.js": "^14.14.1",
"elysia": "^1.3.1",
"ioredis": "^5.6.1",
"mime": "^4.0.6",
"mongodb": "^6.15.0",
"mongoose": "^8.13.0",
"pretty-bytes": "^6.1.1",
"react": "19.1.0",
"react-dom": "19.1.0",
"resend": "^4.5.1",
"sharp": "^0.33.5",
"superjson": "^2.2.2",
"zod": "^3.25.17"
}
}
{
"name": "@workspace/api",
"module": "src/index.ts",
"main": "src/index.ts",
"type": "module",
"scripts": {
"dev": "bun run --watch src/index.ts",
"start": "bun run src/index.ts",
"email": "email dev --port 3002",
"stripe:listen": "stripe listen --forward-to http://localhost:3001/api/auth/stripe/webhook --events \"checkout.session.completed,customer.subscription.updated,customer.subscription.deleted,payment_intent.succeeded,payment_intent.payment_failed\"",
"postinstall": "patch-package"
},
"devDependencies": {
"@types/bun": "^1.2.13",
"@types/cors": "^2.8.18",
"patch-package": "^8.0.0",
"react-email": "4.0.15",
"typescript": "^5.8.2"
},
"peerDependencies": {
"typescript": "^5"
},
"dependencies": {
"@discordjs/rest": "^2.5.0",
"@elysiajs/cors": "^1.3.3",
"@elysiajs/cron": "^1.3.0",
"@elysiajs/trpc": "^1.1.0",
"@elysiajs/websocket": "^0.2.8",
"@react-email/components": "0.0.41",
"@sapphire/framework": "^4.0.0",
"@t3-oss/env-core": "^0.13.4",
"@trpc/client": "^11.1.2",
"@trpc/server": "^11.1.2",
"@vermaysha/discord-webhook": "^1.4.0",
"@workspace/db": "workspace:*",
"@workspace/logger": "workspace:*",
"better-auth": "^1.2.8",
"cors": "^2.8.5",
"discord-api-types": "^0.38.8",
"discord.js": "^14.14.1",
"elysia": "^1.3.1",
"ioredis": "^5.6.1",
"mime": "^4.0.6",
"mongodb": "^6.15.0",
"mongoose": "^8.13.0",
"pretty-bytes": "^6.1.1",
"react": "19.1.0",
"react-dom": "19.1.0",
"resend": "^4.5.1",
"sharp": "^0.33.5",
"superjson": "^2.2.2",
"zod": "^3.25.17"
}
}
Favna
Favna5mo ago
where is 'start:api'? it's not in those scripts
Samu
Samu5mo ago
{
"name": "template",
"version": "0.0.1",
"private": true,
"scripts": {
"build": "turbo build",
"dev": "turbo dev",
"lint": "turbo lint",
"format": "biome format --write",
"start": "turbo start",
"start:api": "turbo start --filter=@workspace/api",
"start:web": "turbo start --filter=web",
"stripe:listen": "stripe listen --forward-to http://localhost:3001/api/auth/stripe/webhook --events \"checkout.session.completed,customer.subscription.created,customer.subscription.updated,customer.subscription.deleted,payment_intent.succeeded,payment_intent.payment_failed\"",
"db": "docker compose up -d",
"postinstall": "patch-package"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"patch-package": "^8.0.0",
"turbo": "^2.4.2",
"typescript": "5.7.3"
},
"packageManager": "bun@1.2.15",
"engines": {
"node": ">=20"
},
"workspaces": ["apps/*", "packages/*", "packages/**/*"],
"dependencies": {
"@better-auth/stripe": "^1.2.8",
"@lexical/react": "^0.31.2",
"hls.js": "^1.6.5",
"motion": "^12.15.0",
"quill": "^2.0.3",
"recharts": "^2.15.3",
"stripe": "18.0.0",
"zustand": "^5.0.5"
}
}
{
"name": "template",
"version": "0.0.1",
"private": true,
"scripts": {
"build": "turbo build",
"dev": "turbo dev",
"lint": "turbo lint",
"format": "biome format --write",
"start": "turbo start",
"start:api": "turbo start --filter=@workspace/api",
"start:web": "turbo start --filter=web",
"stripe:listen": "stripe listen --forward-to http://localhost:3001/api/auth/stripe/webhook --events \"checkout.session.completed,customer.subscription.created,customer.subscription.updated,customer.subscription.deleted,payment_intent.succeeded,payment_intent.payment_failed\"",
"db": "docker compose up -d",
"postinstall": "patch-package"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"patch-package": "^8.0.0",
"turbo": "^2.4.2",
"typescript": "5.7.3"
},
"packageManager": "bun@1.2.15",
"engines": {
"node": ">=20"
},
"workspaces": ["apps/*", "packages/*", "packages/**/*"],
"dependencies": {
"@better-auth/stripe": "^1.2.8",
"@lexical/react": "^0.31.2",
"hls.js": "^1.6.5",
"motion": "^12.15.0",
"quill": "^2.0.3",
"recharts": "^2.15.3",
"stripe": "18.0.0",
"zustand": "^5.0.5"
}
}
Favna
Favna5mo ago
odd. I wonder if turbo messes it up somehow. Can you try this in the dockerfile?
FROM oven/bun:1-alpine

WORKDIR /app

COPY package.json bun.lock ./
COPY packages ./packages
COPY apps/api/package.json ./apps/api/package.json
COPY apps/api/patches ./patches
RUN bun install
RUN bun patch-package

COPY . .

EXPOSE 3001

WORKDIR /app/apps/api

CMD ["bun", "run", "start"]
FROM oven/bun:1-alpine

WORKDIR /app

COPY package.json bun.lock ./
COPY packages ./packages
COPY apps/api/package.json ./apps/api/package.json
COPY apps/api/patches ./patches
RUN bun install
RUN bun patch-package

COPY . .

EXPOSE 3001

WORKDIR /app/apps/api

CMD ["bun", "run", "start"]
Samu
Samu5mo ago
For sure mhh.
[TRACE] [STORE => arguments] [REGISTER] Registered path '/app/apps/api/src/arguments'.
at write (/app/node_modules/@sapphire/framework/dist/cjs/lib/utils/logger/Logger.cjs:37:15)
at trace (/app/node_modules/@sapphire/framework/dist/cjs/lib/utils/logger/Logger.cjs:15:10)
at registerPath (/app/node_modules/@sapphire/pieces/dist/lib/structures/Store.js:98:15)
at registerPath (/app/node_modules/@sapphire/pieces/dist/lib/structures/StoreRegistry.js:82:19)
at login (/app/node_modules/@sapphire/framework/dist/cjs/lib/SapphireClient.cjs:75:19)
at login (/app/node_modules/@sapphire/framework/dist/cjs/lib/SapphireClient.cjs:73:15)
at /app/apps/api/src/index.ts:93:15
[TRACE] [STORE => arguments] [REGISTER] Registered path '/app/apps/api/src/arguments'.
at write (/app/node_modules/@sapphire/framework/dist/cjs/lib/utils/logger/Logger.cjs:37:15)
at trace (/app/node_modules/@sapphire/framework/dist/cjs/lib/utils/logger/Logger.cjs:15:10)
at registerPath (/app/node_modules/@sapphire/pieces/dist/lib/structures/Store.js:98:15)
at registerPath (/app/node_modules/@sapphire/pieces/dist/lib/structures/StoreRegistry.js:82:19)
at login (/app/node_modules/@sapphire/framework/dist/cjs/lib/SapphireClient.cjs:75:19)
at login (/app/node_modules/@sapphire/framework/dist/cjs/lib/SapphireClient.cjs:73:15)
at /app/apps/api/src/index.ts:93:15
several errors like this
Favna
Favna5mo ago
those arent errors. That's just trace logging that it registered the paths
Samu
Samu5mo ago
my bad, dokploy counts them as errors
No description
Samu
Samu5mo ago
wrong term Also we're doing some debugging with the Bot Token so it might take a while
Dawson
DawsonOP5mo ago
No description
Dawson
DawsonOP5mo ago
It is using bun to run the index.ts
Dawson
DawsonOP5mo ago
No description
Favna
Favna5mo ago
hmmm i think a patch to pieces may be needed a new way to detect bun
Dawson
DawsonOP5mo ago
@Samu you can run console.log(Bun.version) if you want to check if it's using bun but this shows it is
Favna
Favna5mo ago
let me quick hotfix this
Dawson
DawsonOP5mo ago
Awesome, thank you
Favna
Favna5mo ago
No description
Solution
Favna
Favna5mo ago
try the new version #Announcements
Samu
Samu5mo ago
Thanks mate! Will do
Dawson
DawsonOP5mo ago
he lied great job lying samu and he just ghost pinged you
Samu
Samu5mo ago
This works amazing!!!! Sorry for the ghost ping @Dawson screw you!
Dawson
DawsonOP5mo ago
Anyways, thank you so much for the help on this!
Samu
Samu5mo ago
Absolutely mate, we do really appreciate it! Great support

Did you find this page helpful?