Zlib-sync failed to resolve

Hi! So I'm trying to integrate discordjs into my Svelte application because I want the bot to send DMs to users on a button press, but I don't want it to actually have any commands. So I created this discordBot.js file as shown and then imported the sendDM() function on one of the pages:
import { getUser } from "$lib/supabase";
import { Client, GatewayIntentBits } from 'discord.js';

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
client.login(import.meta.env.VITE_BOT_TOKEN);

export async function sendDirectDM(discordId, message) {
const user = await client.users.fetch(discordId);
await user.send(message);
}

export async function getUserIdFromUsername(username) {
const user = await client.users.fetch({ username });
return user.id;
}

export async function sendDM(userId, message) {
const user = await getUser(userId);
const discordId = await getUserIdFromUsername(user.discord);
await sendDirectDM(discordId, message);
}
import { getUser } from "$lib/supabase";
import { Client, GatewayIntentBits } from 'discord.js';

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
client.login(import.meta.env.VITE_BOT_TOKEN);

export async function sendDirectDM(discordId, message) {
const user = await client.users.fetch(discordId);
await user.send(message);
}

export async function getUserIdFromUsername(username) {
const user = await client.users.fetch({ username });
return user.id;
}

export async function sendDM(userId, message) {
const user = await getUser(userId);
const discordId = await getUserIdFromUsername(user.discord);
await sendDirectDM(discordId, message);
}
But when I open the page on the localhost which calls one of these functions, it gives me the following error:
Failed to resolve import "zlib-sync" from "node_modules/.vite/deps/discord__js.js?v=f1677f66". Does the file exist?
10:35:55 AM [vite] Internal server error: Failed to resolve import "zlib-sync" from "node_modules/.vite/deps/discord__js.js?v=f1677f66". Does the file exist?
Plugin: vite:import-analysis
File: /Users/x/x/node_modules/.vite/deps/discord__js.js?v=f1677f66:50929:65
50927| }
50928| __name(getInitialSendRateLimitState, "getInitialSendRateLimitState");
Failed to resolve import "zlib-sync" from "node_modules/.vite/deps/discord__js.js?v=f1677f66". Does the file exist?
10:35:55 AM [vite] Internal server error: Failed to resolve import "zlib-sync" from "node_modules/.vite/deps/discord__js.js?v=f1677f66". Does the file exist?
Plugin: vite:import-analysis
File: /Users/x/x/node_modules/.vite/deps/discord__js.js?v=f1677f66:50929:65
50927| }
50928| __name(getInitialSendRateLimitState, "getInitialSendRateLimitState");
I'm not sure what the issue is, and guidance would be very helpful
2 Replies
d.js toolkit
d.js toolkit15mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
seasha
seashaOP15mo ago
discordjs 14.13.0 node 18.16.1 full error:
Failed to resolve import "zlib-sync" from "node_modules/.vite/deps/discord__js.js?v=f1677f66". Does the file exist?
10:35:55 AM [vite] Internal server error: Failed to resolve import "zlib-sync" from "node_modules/.vite/deps/discord__js.js?v=f1677f66". Does the file exist?
Plugin: vite:import-analysis
File: /Users/x/Desktop/x/node_modules/.vite/deps/discord__js.js?v=f1677f66:50929:65
50927| }
50928| __name(getInitialSendRateLimitState, "getInitialSendRateLimitState");
50929| var getZlibSync = (0, import_util2.lazy)(async () => import("zlib-sync").then((mod) => mod.default).catch(() => null));
| ^
50930| var WebSocketShardEvents = ((WebSocketShardEvents2) => {
50931| WebSocketShardEvents2["Closed"] = "closed";
at formatError (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:44055:46)
at TransformContext.error (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:44051:19)
at normalizeUrl (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:41837:33)
at async file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:41991:47
at async Promise.all (index 1)
at async TransformContext.transform (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:41907:13)
at async Object.transform (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:44345:30)
at async loadAndTransform (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:55015:29)
at async viteTransformMiddleware (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:64417:32)
Failed to resolve import "zlib-sync" from "node_modules/.vite/deps/discord__js.js?v=f1677f66". Does the file exist?
10:35:55 AM [vite] Internal server error: Failed to resolve import "zlib-sync" from "node_modules/.vite/deps/discord__js.js?v=f1677f66". Does the file exist?
Plugin: vite:import-analysis
File: /Users/x/Desktop/x/node_modules/.vite/deps/discord__js.js?v=f1677f66:50929:65
50927| }
50928| __name(getInitialSendRateLimitState, "getInitialSendRateLimitState");
50929| var getZlibSync = (0, import_util2.lazy)(async () => import("zlib-sync").then((mod) => mod.default).catch(() => null));
| ^
50930| var WebSocketShardEvents = ((WebSocketShardEvents2) => {
50931| WebSocketShardEvents2["Closed"] = "closed";
at formatError (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:44055:46)
at TransformContext.error (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:44051:19)
at normalizeUrl (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:41837:33)
at async file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:41991:47
at async Promise.all (index 1)
at async TransformContext.transform (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:41907:13)
at async Object.transform (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:44345:30)
at async loadAndTransform (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:55015:29)
at async viteTransformMiddleware (file:///Users/x/Desktop/vscode/x/node_modules/vite/dist/node/chunks/dep-2b82a1ce.js:64417:32)
ic! let me try that, thank you!
Want results from more Discord servers?
Add your server