discord.js icon indicating copy to clipboard operation
discord.js copied to clipboard

Deno Support

Open 7xa5h opened this issue 2 years ago • 2 comments
trafficstars

Which application or package is this feature request for?

discord.js

Feature

Deno, which is a Node.js successor, is a very popular runtime for JavaScript and TypeScript, while I know that most people still use Node.js as its the "industry standard" I also think DJS should add Deno support as it would be pretty easy - I'm not sure, I'm not an expert - and Deno also released NPM package support a long time ago, which would further help here.

I'm pretty sure this wouldnt require a new major version but more of a minor release, as its not that big of a thing imo, Deno is pretty close to how Node.js is and it should be pretty easy, I know lots of people also posted issues like this but I'm trying to get more into detail.

Ideal solution or implementation

To fix this I'd recommend trying to either make a new version of DJS on Denos package registery deno.land/x/ and/or adding support for Deno in the existing NPM library.

Alternative solutions or implementations

You could also simply iron out the bugs that Deno is facing with importing "npm:discord.js" and it would be basically kind of the same fix.

Other context

No response

### Tasks
- [ ] https://github.com/discordjs/discord.js/issues/9645
- [ ] https://github.com/discordjs/discord.js/issues/9666

7xa5h avatar Jun 23 '23 13:06 7xa5h

Dupe of https://github.com/discordjs/discord.js/issues/7065 😄

vladfrangu avatar Jun 23 '23 13:06 vladfrangu

Dupe of #7065 😄

I know, but that issue doesn't specifically mention how Deno has NPM support now and it would be way easier to implement without having to find other 3rd party libraries and packages.

7xa5h avatar Jun 23 '23 13:06 7xa5h

Apparently Deno1.35 now supports discord.js along with some other NPM packages, however, it seems like undici is specifically not working on windows only.

After doing some testing, Deno works on the following systems:

  • [ ] Windows
  • [x] MacOS
  • [x] Most Linux Distros

Here's a related issue: https://github.com/denoland/deno/issues/19766

7xa5h avatar Jul 12 '23 14:07 7xa5h

check #9683

imranbarbhuiya avatar Jul 12 '23 17:07 imranbarbhuiya

Should be closable now- no-de-no-de is merged, which will prevent this issue. Probably.

eris-webserv avatar Jul 17 '23 12:07 eris-webserv

Nope, not fixed. 1.35.1's regression breaks compatibility anyway, and any version below 1.35.0 just returns an API error. :(

eris-webserv avatar Jul 17 '23 13:07 eris-webserv

Try the @dev versions. That should work

vladfrangu avatar Jul 17 '23 13:07 vladfrangu

@dev is what I'm using, silly.

Here's the error:

{
  error: Error: Unexpected server response: 404
    at HttpsClientRequest.<anonymous> (file:///C:/Users/[redacted]/AppData/Local/deno/npm/registry.npmjs.org/ws/8.13.0/lib/websocket.js:888:7)
    at HttpsClientRequest.emit (ext:deno_node/_stream.mjs:1852:9)
    at ext:deno_node/http.ts:476:18
    at eventLoopTick (ext:core/01_core.js:182:11)
}

eris-webserv avatar Jul 17 '23 13:07 eris-webserv

For now, a mitigation strategy is to deno upgrade --version 1.35.0 because that version is confirmed to work fine with Deno. I'll cherrypick through commits to see which one did this...

eris-webserv avatar Jul 17 '23 13:07 eris-webserv

Noo, I see the issue. @dev builds haven't published yet, so the no-de-no-de branch isn't out on npm yet.

vladfrangu avatar Jul 17 '23 13:07 vladfrangu

Aghhhhhhh! Why does it fail with a different error then?! Damn you, Deno and randomly breaking!

~~I'll just grab the file from CI and use that.~~

EDIT: Or you could just manually push dev, yeah, works too

eris-webserv avatar Jul 17 '23 13:07 eris-webserv

Aha, no. It returns the EXACT SAME ERROR on [email protected]

eris-webserv avatar Jul 17 '23 13:07 eris-webserv

Aha, no. It returns the EXACT SAME ERROR on [email protected]

hm so now the latest version of discord.js (when its published to npm) should fix the issue with Deno 1.35.0 and 1.35.1, right?

7xa5h avatar Jul 17 '23 14:07 7xa5h

No, it's not fixed at all.

1.35.0 is fixed on npm:discord.js@dev (Windows), so use 1.35.0. 1.35.1 introduced a different regression that djs couldn't fix.

eris-webserv avatar Jul 17 '23 15:07 eris-webserv

No, it's not fixed at all.

1.35.0 is fixed on npm:discord.js@dev (Windows), so use 1.35.0. 1.35.1 introduced a different regression that djs couldn't fix.

well then when will we stop having to use @dev?

7xa5h avatar Jul 17 '23 15:07 7xa5h

Once discord.js makes a new release

eris-webserv avatar Jul 17 '23 15:07 eris-webserv

Once discord.js makes a new release

hm, ive tested both @dev and @latest, with deno 1.35.0 and 1.35.1 and all 4 of them seem to not work for now. Im still getting the same abort error from undici timing out

7xa5h avatar Jul 17 '23 15:07 7xa5h

are you sure you're on @dev? doesn't happen to me

eris-webserv avatar Jul 17 '23 15:07 eris-webserv

are you sure you're on @dev? doesn't happen to me

yep, heres my code:

import { Client, GatewayIntentBits, Partials } from "npm:discord.js@dev";
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.`))
  // .catch((err) => console.error(`🟥 [LOGIN] ${err}`));

err:

    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:60:31)

Deno 1.35.0, Windows 11 Lite (basically Tiny 11)

7xa5h avatar Jul 17 '23 15:07 7xa5h

Not sure if W11 Lite is the problem. All I know is stock Windows 11 works fine.

eris-webserv avatar Jul 17 '23 21:07 eris-webserv

Can you verify that the latest dev release is using fetch instead of undici for deno?

suneettipirneni avatar Jul 17 '23 21:07 suneettipirneni

Can you verify that the latest dev release is using fetch instead of undici for deno?

well not in my case as you can clearly see undici in the error log, ill check the latest dev version tmr tho

7xa5h avatar Jul 18 '23 02:07 7xa5h

Deno has pushed a commit to patch the regression in 1.35.1, next Deno release will be able to natively run discord.js.

For now, deno upgrade --canary will move you to the patched version of Deno.

eris-webserv avatar Jul 19 '23 00:07 eris-webserv

For what it's worth, once we release new versions of all modules you also can do that 😄

vladfrangu avatar Jul 19 '23 00:07 vladfrangu

Nope- it's not working for everyone on @dev. It seems to be local to 7xa5h- BUT some things use the Node ws module, which is unreliable on Deno to say the least.

eris-webserv avatar Jul 19 '23 00:07 eris-webserv

Nope- it's not working for everyone on @dev. It seems to be local to 7xa5h- BUT some things use the Node ws module, which is unreliable on Deno to say the least.

do i close the issue now? i mean its practically fixed from both sides now

7xa5h avatar Jul 19 '23 07:07 7xa5h