Cant resolve zlib-sync

When using discordjs/core, I get the following error message
./node_modules/@discordjs/ws/dist/index.mjs:522:36
Module not found: Can't resolve 'zlib-sync'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/@discordjs/core/dist/index.mjs
./src/lib/utils/discord.ts
./src/app/(dashboard)/guild/[guildId]/page.tsx
./node_modules/@discordjs/ws/dist/index.mjs:522:36
Module not found: Can't resolve 'zlib-sync'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/@discordjs/core/dist/index.mjs
./src/lib/utils/discord.ts
./src/app/(dashboard)/guild/[guildId]/page.tsx
Not sure whats going on
No description
26 Replies
chillihero
chilliheroOP•17mo ago
these are the deps i have
"dependencies": {
"@discordjs/core": "^0.6.0",
"@discordjs/rest": "^1.7.1",
"@sapphire/eslint-config": "^4.4.2",
"@sapphire/prettier-config": "^1.4.5",
"@sapphire/ts-config": "^4.0.0",
"discord-api-types": "^0.37.48",
"discord-oauth2": "^2.11.0",
"eslint": "8.44.0",
"eslint-config-next": "13.4.9",
"jotai": "^2.2.1",
"next": "13.4.9",
"next-auth": "^4.22.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-icons": "^4.10.1",
"theme-change": "^2.5.0"
},
"dependencies": {
"@discordjs/core": "^0.6.0",
"@discordjs/rest": "^1.7.1",
"@sapphire/eslint-config": "^4.4.2",
"@sapphire/prettier-config": "^1.4.5",
"@sapphire/ts-config": "^4.0.0",
"discord-api-types": "^0.37.48",
"discord-oauth2": "^2.11.0",
"eslint": "8.44.0",
"eslint-config-next": "13.4.9",
"jotai": "^2.2.1",
"next": "13.4.9",
"next-auth": "^4.22.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-icons": "^4.10.1",
"theme-change": "^2.5.0"
},
oke seems like not a really discord related https://bobbyhadz.com/blog/module-not-found-error-cant-resolve-path#module-not-found-cant-resolve-zlib-error More a "trying to use a nodejs function in the frontend" issue. so the following throws the error:
// page.tsx

import { API } from '@discordjs/core';
import { REST } from '@discordjs/rest';

export default async function Guild({ params }: { params: { guildId: string } }) {
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN);
const api = new API(rest);
const guildInfos = await api.guilds.get(params.guildId);

return (
<div>
My Guild: {params.guildId} <br />
{JSON.stringify(guildInfos, null, 2)}
</div>
);
}
// page.tsx

import { API } from '@discordjs/core';
import { REST } from '@discordjs/rest';

export default async function Guild({ params }: { params: { guildId: string } }) {
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN);
const api = new API(rest);
const guildInfos = await api.guilds.get(params.guildId);

return (
<div>
My Guild: {params.guildId} <br />
{JSON.stringify(guildInfos, null, 2)}
</div>
);
}
this is a server component, so it is not rendered on the clientside? when it says its a node function, does it need to be in an api route to work?
kyra
kyra•17mo ago
Use @discordjs/core/http-only
chillihero
chilliheroOP•17mo ago
oh install this package? or import it when importing API from core?
kyra
kyra•17mo ago
Also, you want to... share rest and api as a singleton somewhere If you create new instances over and over, you won't have ratelimits Import
chillihero
chilliheroOP•17mo ago
yea, ill create a util class for this
kyra
kyra•17mo ago
It's a subpath You don't need a util class for this You'd be wrapping an util class with an util class
chillihero
chilliheroOP•17mo ago
No description
kyra
kyra•17mo ago
Use moduleResolution: 'bundler' in your TS config
chillihero
chilliheroOP•17mo ago
what does this do?
kyra
kyra•17mo ago
Respect the exports from package.json Similar to node16 and nodenext, but more suited for web
kyra
kyra•17mo ago
Yeah, exactly what I said, set that
chillihero
chilliheroOP•17mo ago
now the import works but it still runs into the zlib issue
kyra
kyra•17mo ago
It shouldn't
chillihero
chilliheroOP•17mo ago
pepeFeelsBadManhttps://github.com/BirthdayyBot/dashboard/blob/develop/src/app/(dashboard)/guild/%5BguildId%5D/page.tsx thats the page btw, maybe anything else that could cause this? oh bruh restarting vscode always helps lmfao tysm, ur awesome chilliLove
chillihero
chilliheroOP•17mo ago
what is the difference when deploying on vercel? https://vercel.com/birthdayy/birthdayy-dashboard/5Qxypnw9j6BBTsV5zT3FZG492dWH (nvm you cannot see this) Cause vercel still fails to find the zlib lmao reproducable when using yarn build locally
kyra
kyra•17mo ago
What if you install dev? 🤔
chillihero
chilliheroOP•17mo ago
okay im just to stupid sometimes, sorry theonly issue now, is that i want to import discord.js in another place to use the permission bitfield
kyra
kyra•17mo ago
You can use @sapphire/bitfield
chillihero
chilliheroOP•17mo ago
and as far as I understood it imports discord.js ws ah
kyra
kyra•17mo ago
Hence why @discordjs/core/http-only
chillihero
chilliheroOP•17mo ago
can I create a bitfield from a number there?
kyra
kyra•17mo ago
Read the docs
chillihero
chilliheroOP•17mo ago
its expecting a Record on it
kyra
kyra•17mo ago
Docs = README Yeah, just pass PermissionsFlagBits Then reuse it as your PermissionsBitField object
chillihero
chilliheroOP•17mo ago
i don't follow my brain is not functional rn, im sorry haha think imma take a break, this cant be that complicated
Want results from more Discord servers?
Add your server