denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.41k stars 5.18k forks source link

`discord.js` support with Deno 1.35 #19766

Open 7xa5h opened 1 year ago

7xa5h commented 1 year ago

The recent Deno 1.35 release announced support for popular NPM libraries, including discord.js. However, when testing Deno v1.35 with the latest discord.js version, I encountered an AbortError with the message "Request Aborted". This issue persists despite the claimed support for discord.js in the Deno 1.35 release.

img

The AbortError destroys functionality of discord.js applications in Deno, making it impossible to use alongside Deno. This issue has persisted even before the Deno 1.35 release.

The specific code is a basic boilerplate code that I adapted from discordjs.guide to make it compatible with Deno, which you can see below:

import { Client, Events, GatewayIntentBits } from "discord.js";

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.once(Events.ClientReady, c => {
    console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.login("placeholder"); // a valid token

Versions: deno 1.35.0 (release, x86_64-pc-windows-msvc) v8 11.6.189.7 typescript 5.1.6 discord.js 14.11.0

Erisfiregamer1 commented 1 year ago

This is an issue with Windows only (Specifically, any terminal for Windows outside of WSL since that's a Linux VM and it works fine there?!). Powershell, Git Bash, and CMD are affected.

What's going on? Discord.js (or undici) is timing out getting the gateway URL to be used for requests.

Is there a workaround? Use WSL. It doesn't happen in WSL, just Windows. (Windows Subsystem for Linux)

7xa5h commented 1 year ago

This is an issue with Windows only (Specifically, any terminal for Windows outside of WSL since that's a Linux VM and it works fine there?!). Powershell, Git Bash, and CMD are affected.

What's going on? Discord.js (or undici) is timing out getting the gateway URL to be used for requests.

Is there a workaround? Use WSL. It doesn't happen in WSL, just Windows. (Windows Subsystem for Linux)

Would a Linux terminal emulator like cygwin or mysys2 fix the issue?

Erisfiregamer1 commented 1 year ago

This is an issue with Windows only (Specifically, any terminal for Windows outside of WSL since that's a Linux VM and it works fine there?!). Powershell, Git Bash, and CMD are affected. What's going on? Discord.js (or undici) is timing out getting the gateway URL to be used for requests. Is there a workaround? Use WSL. It doesn't happen in WSL, just Windows. (Windows Subsystem for Linux)

Would a Linux terminal emulator like cgywin or mysys2 fix the issue?

Also on another note how does that imply that discord.js is now supported when it clearly doesnt work on 1 of the most used operating systems?

Discord.js is supported, Windows is just being :skull: as usual. I doubt a terminal emulator would help. :(

Erisfiregamer1 commented 12 months ago

This is me, not being happy with you. >:/

Why? Because Deno 1.35.1 introduced a regression that broke discord.js!!!

image

This error does NOT OCCUR prior to Deno 1.35.1 (Deno 1.35 works fine). The newest version of Deno introduced this regression!!!! This is also a non-specific regression- every OS is affected.

Erisfiregamer1 commented 11 months ago

no-de-no-de on Discord.js has been merged. This should have solved the issue. Let me test that.

EDIT: Windows works fine now (On 1.35.0), BUT the existing regression on 1.35.1 still exists. The windows tag should be removed. If you want to use discord.js run deno upgrade --version 1.35.0 to revert to 1.35.0.

Erisfiregamer1 commented 11 months ago

Time to wait for Deno to make a release again so I don't have to use Canary...

7xa5h commented 11 months ago

hm, after updating to Deno 1.35.2 it seems like im still getting the same error. is there any chance its being caused by my operating system, as im not using stock windows 11 but rather Mini11, a lightweight version without all the ms apps. heres the error message

error: Uncaught AbortError: Request aborted
    at abort (file:///C:/Users/xash/AppData/Local/deno/npm/registry.npmjs.org/undici/5.22.1/lib/api/abort-signal.js:10:18)
    at AbortSignal.self.<computed> (file:///C:/Users/xash/AppData/Local/deno/npm/registry.npmjs.org/undici/5.22.1/lib/api/abort-signal.js:29:5)
    at innerInvokeEventListeners (ext:deno_web/02_event.js:792:7)
    at invokeEventListeners (ext:deno_web/02_event.js:839:5)
    at dispatch (ext:deno_web/02_event.js:696:9)
    at AbortSignal.dispatchEvent (ext:deno_web/02_event.js:1101:12)
    at AbortSignal.[[[signalAbort]]] (ext:deno_web/03_abort_signal.js:97:10)
    at AbortController.abort (ext:deno_web/03_abort_signal.js:170:30)
    at Timeout._onTimeout (file:///C:/Users/xash/AppData/Local/deno/npm/registry.npmjs.org/@discordjs/rest/1.7.1/dist/index.js:589:71)
    at cb (ext:deno_node/internal/timers.mjs:63:31)

versions: deno 1.35.2 (release, x86_64-pc-windows-msvc) v8 11.6.189.7 typescript 5.1.6

bartlomieju commented 11 months ago

It's hard to say. We'll try to reproduce the problem on Windows.

Erisfiregamer1 commented 11 months ago

Works for me on 1.35.2

Maybe this is Mini11? @7xa5h try in a w11 VM pls (not mini11, full w11)

7xa5h commented 11 months ago

Works for me on 1.35.2

Maybe this is Mini11? @7xa5h try in a w11 VM pls (not mini11, full w11)

I unfortunately cant, as my system cant even support windows 11 atm. But i have contacted one of the Mini11 developers and he was pretty sure it wasnt an issue with Mini11. However, if you can, and want, you could test it on Mini11 as the setup is very very lightweight and seamless

Erisfiregamer1 commented 11 months ago

The w11 requirements are a joke and can easily be bypassed.

7xa5h commented 11 months ago

The w11 requirements are a joke and can easily be bypassed.

my computer simply cant handle them lol, its like a really low end crappy laptop

KohnoseLami commented 11 months ago

I use Windows 11 Pro and it doesn't work with similar errors.

PS D:\Desktop\Projects\Discord\Deno> deno run --allow-all index.ts
error: Uncaught AbortError: Request aborted
    at abort (file:///D:/Desktop/Projects/Discord/Deno/node_modules/.deno/undici@5.22.1/node_modules/undici/lib/api/abort-signal.js:10:18)
    at AbortSignal.self.<computed> (file:///D:/Desktop/Projects/Discord/Deno/node_modules/.deno/undici@5.22.1/node_modules/undici/lib/api/abort-signal.js:29:5)
    at innerInvokeEventListeners (ext:deno_web/02_event.js:792:7)
    at invokeEventListeners (ext:deno_web/02_event.js:839:5)
    at dispatch (ext:deno_web/02_event.js:696:9)
    at AbortSignal.dispatchEvent (ext:deno_web/02_event.js:1101:12)
    at AbortSignal.[[[signalAbort]]] (ext:deno_web/03_abort_signal.js:97:10)
    at AbortController.abort (ext:deno_web/03_abort_signal.js:170:30)
    at Timeout._onTimeout (file:///D:/Desktop/Projects/Discord/Deno/node_modules/.deno/discord.js@14.7.1/node_modules/@discordjs/rest/dist/index.js:589:71)
    at cb (ext:deno_node/internal/timers.mjs:63:31)

image deno 1.35.2 (release, x86_64-pc-windows-msvc) v8 11.6.189.7 typescript 5.1.6

https://github.com/denoland/deno/issues/19532 Does discord.js use undici, so it won't work until the undici problem is resolved?

7xa5h commented 11 months ago

19532 Does discord.js use undici, so it won't work until the undici problem is resolved?

Discord.js does use undici, no-de-no-de was supposed to changed that but the dev builds for me all also used undici and not native fetch(), maybe we'll simply have to wait for either Deno to support undici or for djs to release a new version

Erisfiregamer1 commented 11 months ago

I use Windows 11 Pro and it doesn't work with similar errors.

PS D:\Desktop\Projects\Discord\Deno> deno run --allow-all index.ts
error: Uncaught AbortError: Request aborted
    at abort (file:///D:/Desktop/Projects/Discord/Deno/node_modules/.deno/undici@5.22.1/node_modules/undici/lib/api/abort-signal.js:10:18)
    at AbortSignal.self.<computed> (file:///D:/Desktop/Projects/Discord/Deno/node_modules/.deno/undici@5.22.1/node_modules/undici/lib/api/abort-signal.js:29:5)
    at innerInvokeEventListeners (ext:deno_web/02_event.js:792:7)
    at invokeEventListeners (ext:deno_web/02_event.js:839:5)
    at dispatch (ext:deno_web/02_event.js:696:9)
    at AbortSignal.dispatchEvent (ext:deno_web/02_event.js:1101:12)
    at AbortSignal.[[[signalAbort]]] (ext:deno_web/03_abort_signal.js:97:10)
    at AbortController.abort (ext:deno_web/03_abort_signal.js:170:30)
    at Timeout._onTimeout (file:///D:/Desktop/Projects/Discord/Deno/node_modules/.deno/discord.js@14.7.1/node_modules/@discordjs/rest/dist/index.js:589:71)
    at cb (ext:deno_node/internal/timers.mjs:63:31)

image deno 1.35.2 (release, x86_64-pc-windows-msvc) v8 11.6.189.7 typescript 5.1.6

19532 Does discord.js use undici, so it won't work until the undici problem is resolved?

use discord.js@dev, main d.js uses Undici still

7xa5h commented 11 months ago

use discord.js@dev, main d.js uses Undici still

in my case even @dev uses Undici

7xa5h commented 11 months ago

any updates on this?

Erisfiregamer1 commented 11 months ago

I've been testing this over and over and cannot reproduce. It sounds like a localized problem.

@KohnoseLami hasn't responded with the results of using @dev so we can only assume that was the problem. You're on an unsupported distro that might be messing with djs's ability to determine you're using Deno.

KohnoseLami commented 11 months ago

Oh, sorry. I haven't been able to reply.

I get similar errors when I use @dev as well.

image

PS D:\Desktop\Projects\Discord\Deno> deno run --unstable --allow-all index.ts
error: Uncaught AbortError: Request aborted
    at abort (file:///D:/Desktop/Projects/Discord/Deno/node_modules/.deno/undici@5.22.1/node_modules/undici/lib/api/abort-signal.js:10:18)
    at AbortSignal.self.<computed> (file:///D:/Desktop/Projects/Discord/Deno/node_modules/.deno/undici@5.22.1/node_modules/undici/lib/api/abort-signal.js:29:5)
    at innerInvokeEventListeners (ext:deno_web/02_event.js:792:7)
    at invokeEventListeners (ext:deno_web/02_event.js:839:5)
    at dispatch (ext:deno_web/02_event.js:696:9)
    at AbortSignal.dispatchEvent (ext:deno_web/02_event.js:1101:12)
    at AbortSignal.[[[signalAbort]]] (ext:deno_web/03_abort_signal.js:97:10)
    at AbortController.abort (ext:deno_web/03_abort_signal.js:170:30)
    at Timeout._onTimeout (file:///D:/Desktop/Projects/Discord/Deno/node_modules/.deno/discord.js@14.7.2-dev.1670069017-86959ba.0/node_modules/@discordjs/rest/dist/index.js:589:71)
    at cb (ext:deno_node/internal/timers.mjs:63:31)

https://github.com/denoland/deno/issues/19766#issuecomment-1646246183 I agree with this comment. discord.js still used undici, and no-de-no-de didn't seem to completely remove it. https://github.com/discordjs/discord.js/pull/9683/files I'm not sure what the main change in this pull request was, but at least it doesn't seem to complete change the undici implementation in discord.js to a fetch implementation.

So I don't think you can use discord.js with Deno on Windows unless the deno project either improves compatibility with undici or gets rid of it from discord.js. https://github.com/discordjs/discord.js/pull/9683/files

7xa5h commented 11 months ago

Wait, if https://github.com/denoland/deno/commit/51b3534b3d3833667e8c029564bebf319b0d2596 didnt fix the undici issue then what did it even do?

Erisfiregamer1 commented 11 months ago

That's the neat part, it should have.

On my environment, it uses native Deno (evidenced by an ENTIRELY DIFFERENT ERROR MESSAGE).

vladfrangu commented 11 months ago

Hey, author of the no-de-no-de PR here.

Would like to clarify a few things about the PR, why installing @dev isn't working (there's 2 reasons) and hopefully that'll help out a bit.

Undici isn't going away in node at this time (or probably ever). After the PR is released properly, using @discordjs/rest in deno/bun/cf workers/etc (or installing a discord.js version that uses a version of @discordjs/rest that has the branch in) will use native fetch instead of undici. This is done because undici's request is much faster than fetch in the current node implementation (there's some issues opened for performance issues related to this).

Currently you cannot use @dev for two reasons:

Unfortunately your best bet is to either hopefully ses this issue solved (some people have it, some don't, I've consistently gotten it but know someone who hasn't on the same deno version), or be patient until we release and bump everything (which I cannot give an ETA for).

Hope that helps. If you're looking for instructions on how I tested the changes out I can probably write them in a gist when back

7xa5h commented 11 months ago

Undici isn't going away in node at this time (or probably ever). After the PR is released properly, using @discordjs/rest in deno/bun/cf workers/etc (or installing a discord.js version that uses a version of @discordjs/rest that has the branch in) will use native fetch instead of undici. This is done because undici's request is much faster than fetch in the current node implementation (there's some issues opened for performance issues related to this).

Could you clarify what you mean by "going away in node", isn't the fix supposed to be in djs itself? Another question whats the difference between /rest and the normal version of discord.js (sorry i kinda dk alot ab djs)

Erisfiregamer1 commented 11 months ago

Undici isn't going away in node at this time (or probably ever). After the PR is released properly, using @discordjs/rest in deno/bun/cf workers/etc (or installing a discord.js version that uses a version of @discordjs/rest that has the branch in) will use native fetch instead of undici. This is done because undici's request is much faster than fetch in the current node implementation (there's some issues opened for performance issues related to this).

Could you clarify what you mean by "going away in node", isn't the fix supposed to be in djs itself? Another question whats the difference between /rest and the normal version of discord.js (sorry i kinda dk alot ab djs)

/rest is a package used by djs for requests to Discord's API. It's the underlying cause of your errors since Undici Nonsense

7xa5h commented 11 months ago

could someone quickly check if 1.36 fixes the issue as i dont currently have my devices EDIT: ive seen that discord.js has made a new release could anyone also check that too

7xa5h commented 10 months ago

it seems that the issue is fixed, ive tested it on my Windows machine alongside Deno 1.36.1 and DJS 14.12.1, however i still see an "error" that i dont quite understand, could smeone explain what ClientRequest.options.createConnection means? image

import { Client, GatewayIntentBits, Partials } from "npm:discord.js@14.12.1";
import config from "./config.json" assert { type: "json" };

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GuildMessages,
  ],
  partials: [
    Partials.Channel,
    Partials.GuildMember,
    Partials.Reaction,
    Partials.ThreadMember,
    Partials.User,
  ],
});

// client.config = config;

client
  .login(config.token)
  .then(() => console.log(`🟩 [LOGIN] Client logged in as ${client.user?.username}`))
  // .catch((err) => console.error(`🟥 [LOGIN] ${err}`));
Erisfiregamer1 commented 10 months ago

That's just the main way some packages do websockets. There's always a fallback, so don't worry :)

libewa commented 10 months ago

so as i understand this, djs works with the integrated workaround?

Erisfiregamer1 commented 10 months ago

so as i understand this, djs works with the integrated workaround?

Not exactly. There's no workaround, they've just added code to use the native Websocket implementation other JS runtimes provide (ex. Deno).

vladfrangu commented 10 months ago

so as i understand this, djs works with the integrated workaround?

Not exactly. There's no workaround, they've just added code to use the native Websocket implementation other JS runtimes provide (ex. Deno).

REST* implementation (via global fetch). Native websocket is waiting on Bun to fix their WS Client