#Module Not Found errors, trying to use @discordjs/core v0.6.0 with nextjs v13.4.6

24 messages · Page 1 of 1 (latest)

peak yew
#

A totally fresh project, I assume nextjs and @discordjs/core might be having some conflicts, but I don't find zlib-sync to be a common dep b/w next.js so I don't thing thats a valid reason.

error

- error ./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
./app/page.tsx

Home Page (and the only page using @discordjs/core)

import { REST } from '@discordjs/rest';
import { API } from '@discordjs/core';
export default async function Home() {
  const rest = new REST({ version: '10' })
  const api = new API(rest);
  const commands = await api.applicationCommands.getGlobalCommands('id')
  return (
    <main>
      {commands.map((command) => { return <div key={command.id}>{command.name}</div> })}
      </main>
  )
}

npm ls

├── @discordjs/core@0.6.0
├── @types/node@20.3.1
├── @types/react-dom@18.2.6
├── @types/react@18.2.13
├── autoprefixer@10.4.14
├── eslint-config-next@13.4.6
├── eslint@8.43.0
├── next@13.4.6
├── postcss@8.4.24
├── react-dom@18.2.0
├── react@18.2.0
├── tailwindcss@3.3.2
└── typescript@5.1.3

Minimum reproducible code
npx create-next-app@latest
the image has the options setted while configuring the next-app
npm i @discordjs/core

paste this in /app/page.tsx

import { REST } from '@discordjs/rest';
import { API } from '@discordjs/core';
export default async function Home() {
  const rest = new REST({ version: '10' })
  const api = new API(rest);
  const commands = await api.applicationCommands.getGlobalCommands('id')
  return (
    <main>
      {commands.map((command) => { return <div key={command.id}>{command.name}</div> })}
      </main>
  )
}
modest ledgeBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

peak yew
#

node version is v20.3.0, forgot to mention

lost rune
#

Do You want the http-only version of core? need to import from @discordjs/core/http-only

peak yew
lost rune
#

Since you don’t use a gateway but only the REST API you probably want http-only (no websocket)

peak yew
#

http-only doesn't seem be a valid directory

Cannot find module '@discordjs/core/http-only' or its corresponding type declarations.
#

and @discordjs/core/dist/http-only which exists doesn't export a package

#
Package path ./dist/http-only is not exported from package C:\Users\{name}\OneDrive\Desktop\po\proj2\node_modules\@discordjs\core
lost rune
#

Yeah, /http-only is exported though, not as /dist/…

peak yew
#

I'm sharing my tsconfig and package.json too, if this might be the missing key

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}
{
  "name": "proj2",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@discordjs/core": "^0.6.0",
    "@types/node": "20.3.1",
    "@types/react": "18.2.13",
    "@types/react-dom": "18.2.6",
    "autoprefixer": "10.4.14",
    "eslint": "8.43.0",
    "eslint-config-next": "13.4.6",
    "next": "13.4.6",
    "postcss": "8.4.24",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "tailwindcss": "3.3.2",
    "typescript": "5.1.3"
  }
}
lost rune
peak yew
#

while trying to import api

import {API} from '@discordjs/core/http-only';

ts throws the error

#

Ok so I realised that it indeed export http-only, it's just that there are no types exported with it

const {REST} = require('@discordjs/rest')
const {API} = require('@discordjs/core/http-only')
const rest = new REST({ version: '10'}).setToken("sd")
const api = new API(rest);
const commands = api.applicationCommands.getGlobalCommands('1117540238961692773')
console.log(commands)

this js code works in a completely new project (only @discordjs/core installed), though it doesn't throw any Module-Not-Found Errors without using http-only

lost rune
#

It does export types though…Thonk does restarting ts-server help?

peak yew
#

uh really really really sorry for the annoyance, restarting ts-server fixed..
also wanted to ask one more thing, I want to use CLIENT_ID and CLIENT_SECRET only for retrieving global/guild commands? can I initiate the REST client without token Thinkeng
nvm figured it

#

THANKS THOUGH!!!!!!!!!!!!!!!!!!!!!!!!

rancid grotto
#

default utils from repo template

import process from 'node:process';
import { URL } from 'node:url';
import { API } from '@discordjs/core/http-only';
import { REST } from 'discord.js';
import { loadCommands } from './loaders.js';

const commands = await loadCommands(new URL('commands/', import.meta.url));
const commandData = [...commands.values()].map((command) => command.data);

const rest = new REST({ version: '10' }).setToken(process.env.TOKEN!);
const api = new API(rest);

const result = await api.applicationCommands.bulkOverwriteGlobalCommands(process.env.APPLICATION_ID!, commandData);

console.log(`Successfully registered ${result.length} commands.`);

rancid grotto
#

for now, I asked chatGPT to fix it by not using https-only
not sure how the library works or if this even works as GPT is cancer
please correct me if its wrong

import { URL } from 'node:url';
import { REST } from 'discord.js';
import { loadCommands } from './loaders.js';

const commands = await loadCommands(new URL('commands/', import.meta.url));
const commandData = [...commands.values()].map((command) => command.data);

const rest = new REST({ version: '10' }).setToken(process.env.TOKEN!);

// Register global commands
const result = await rest.put('/applications/{application.id}/commands', {
  body: commandData,
});

console.log(`Successfully registered ${result} commands.`);
lost rune
rancid grotto
#

A) because this is the most recent and ONLY conversation with https-only in a ts environment
B) from 'npm create discord-bot' with typescript

#

there are no typings being detected from https-only and so running tsc throws the same error as above