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

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
- 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>
)
}
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
├── @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>
)
}
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>
)
}
5 Replies
d.js toolkit
d.js toolkit2y ago
• 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.
im6_
im6_OP2y ago
node version is v20.3.0, forgot to mention I don't know what is the http-only version, but simply I just want to deal with setting and getting ApplicationCommands, both guild and global commands http-only doesn't seem be a valid directory
Cannot find module '@discordjs/core/http-only' or its corresponding type declarations.
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
Package path ./dist/http-only is not exported from package C:\Users\{name}\OneDrive\Desktop\po\proj2\node_modules\@discordjs\core
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"]
}
{
"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"
}
}
{
"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"
}
}
while trying to import api
import {API} from '@discordjs/core/http-only';
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)
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 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!!!!!!!!!!!!!!!!!!!!!!!!
digimbyte
digimbyte14mo ago
I restarted the ts server with no fix, I have updated the core install to 1.0.1 to ensure REST is updated for commands. any insight into fixes from the create-bot solution?
digimbyte
digimbyte14mo ago
No description
digimbyte
digimbyte14mo ago
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.`);
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.`);
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.`);
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.`);
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 the entire point of forums is to categorize and discuss on particular issues compared to standard conversation threads.
Want results from more Discord servers?
Add your server