C
Carbon2mo ago
Asleep

TypeError when importing any command or Client

Hey. When I import either of these 2 classes, I get this error.
import { Client, ClientMode } from "@buape/carbon"
import CommandHandler from "~/server/discord/handler";
import { Client, ClientMode } from "@buape/carbon"
import CommandHandler from "~/server/discord/handler";
TypeError: Cannot read properties of undefined (reading 'Base') This is the contents of handler.ts:
import { Command, type CommandInteraction } from "@buape/carbon";
import { db } from "~/server/db";

export default class CommandHandler extends Command {
name = "*"
description = "CarbonCraft Command Handler"
defer = false

async run(interaction: CommandInteraction) {
const command = await db.command.findFirst({
where: {
botId: interaction.client.options.clientId,
name: interaction.rawData.data.name
}
})
return interaction.reply({
content: command?.response
})
}
}
import { Command, type CommandInteraction } from "@buape/carbon";
import { db } from "~/server/db";

export default class CommandHandler extends Command {
name = "*"
description = "CarbonCraft Command Handler"
defer = false

async run(interaction: CommandInteraction) {
const command = await db.command.findFirst({
where: {
botId: interaction.client.options.clientId,
name: interaction.rawData.data.name
}
})
return interaction.reply({
content: command?.response
})
}
}
Solution:
I must've been doing something wrong the first, time turbopack appears to fix it now
Jump to solution
15 Replies
Apteryx
Apteryx2mo ago
What is the full stack trace? And what runtime and bundler are you using?
Asleep
Asleep2mo ago
I'm trying to make a bot builder using Carbon. This is my interactions endpoint, and where it errors upon import.
import type { NextApiRequest, NextApiResponse } from "next";
import { db } from "~/server/db";
import { Client, ClientMode } from "@buape/carbon"
import CommandHandler from "~/server/discord/handler";

export async function POST(req: NextApiRequest, res: NextApiResponse) {
if (!req.body.data) return res.status(400);
const bot = await db.bot.findFirst({
where: {
"clientId": req.body.application_id
}
})
console.log(bot)
if (!bot) return res.status(401);
const client = new Client({
clientId: bot.clientId,
publicKey: bot.publicKey,
token: bot.token,
mode: ClientMode.Web
}, [
new CommandHandler()
])

await client.router.fetch(req.body)
}
import type { NextApiRequest, NextApiResponse } from "next";
import { db } from "~/server/db";
import { Client, ClientMode } from "@buape/carbon"
import CommandHandler from "~/server/discord/handler";

export async function POST(req: NextApiRequest, res: NextApiResponse) {
if (!req.body.data) return res.status(400);
const bot = await db.bot.findFirst({
where: {
"clientId": req.body.application_id
}
})
console.log(bot)
if (!bot) return res.status(401);
const client = new Client({
clientId: bot.clientId,
publicKey: bot.publicKey,
token: bot.token,
mode: ClientMode.Web
}, [
new CommandHandler()
])

await client.router.fetch(req.body)
}
Shadow
Shadow2mo ago
Base definitely does exist, BaseInteraction pulls it from index.js where it does exist there too
No description
Asleep
Asleep2mo ago
Yeah, that’s what’s weird about it. I’ve tried reinstalling the package to no avail.
Apteryx
Apteryx2mo ago
It's more related to webpack/next. Base is defined, Module isn't which is what webpack seems to be star importing carbon as. Tho I have no idea why or how to solve this, Evaluate is run on Next to so it is possible to do. What version of next.js are you using? Are you using turbopack?
Asleep
Asleep2mo ago
Next.js 14.2.11. I am not using turbopack. I'm currently experimenting to see where exactly it's erroring. I don't think it's at import anymore. I've gotten it to import in an API route. Okay. It seems to appear when I initialize the Client. I can't access the base class by itself either. I created a post in the Next support server.
Shadow
Shadow5w ago
I'm having this same issue in a bare bones repo, nextjs 14.2.11 without turbopack
Kiai
Kiai5w ago
Level Up!
Congratulations <@439223656200273932>, you leveled up to level 2!
Shadow
Shadow5w ago
Switching to turbopack seems to resolve it though (@Apteryx @Asleep) It also looks like webpack in production works fine, its just dev mode
Asleep
Asleep5w ago
I can try that again.
Shadow
Shadow5w ago
GitHub
GitHub - thewilloftheshadow/carbon-nextjs-test
Contribute to thewilloftheshadow/carbon-nextjs-test development by creating an account on GitHub.
Asleep
Asleep5w ago
I have time, gonna try again
Solution
Asleep
Asleep5w ago
I must've been doing something wrong the first, time turbopack appears to fix it now
Asleep
Asleep5w ago
issue fixed ✅
Want results from more Discord servers?
Add your server