discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.27k stars 3.96k forks source link

Minimum node version requirement: >=16.6.0 #5119

Closed iCrawl closed 3 years ago

iCrawl commented 3 years ago

Starting with v13.0.0 the minimum node version requirement for discord.js will be >=16.6.0 to make use of features like optional chaining, (ES2021) etc.

Benefits:

Drawbacks:

ElianCordoba commented 3 years ago

Another drawback is that Node 14 is marked as beta in Firebase functions. Not your fault of course, it's little bit scary to make the upgrade.

kyranet commented 3 years ago

Node.js v14 is also LTS, not bleeding edge, alpha, nor beta; it's stable and it's the recommended version, which makes it a reasonable target: image

Either way, by the time we release discord.js@13.0.0, Firebase and other hosting platforms should be updated, and if not, there'll most likely be a margin of a couple of months to upgrade (before v12 stops working due to v6 and v7 shutdown on Discord's side), if not, that'll be unfortunate, but Node.js v14 comes with new JavaScript features that improve the entire library's maintainability, stability, and to some extent, also performance.

ElianCordoba commented 3 years ago

Yeah I always though that hosting platforms not encouringing, or even worse, not offering new versions of the runtimes would basically hold back a big chunk of the ecosystem.

LevitatingBusinessMan commented 3 years ago

Nice, my bot still runs on node 8 and discord.js 11 But I think discord.js 11 just broke a few days back....

PyroTechniac commented 3 years ago

v11 hasn't been supported in a long time, and was recently broken permanently with the addition of stage channels

ghost commented 3 years ago

Then discord.js v13 will not work on Replit ๐Ÿ˜ฆ

castdrian commented 3 years ago

Correct. This is already thankfully the case.

abdulrahman1s commented 3 years ago

@Sly-Little-Fox

Then discord.js v13 will not work on replit

You still can install newer version of node in replit Simply type npm i node@14 in shell.. and enjoy! ๐Ÿ™‚

ghost commented 3 years ago

@Sly-Little-Fox

Then discord.js v13 will not work on replit

You still can install newer version of node in replit Simply type npm i node@14 in shell.. and enjoy! slightly_smiling_face

Thank you! I prefer using n or nvm though.

torohangupta commented 3 years ago

@Sly-Little-Fox

Then discord.js v13 will not work on replit

You still can install newer version of node in replit Simply type npm i node@14 in shell.. and enjoy! ๐Ÿ™‚

I just tested it- it doesn't look like that works- I still get an error thrown when I attempt to run a v13 bot. Looking at some comments online, it seems like Repl.it doesn't like other versions of Node... unless there's a glaring issue I've overlooked and the answer was a switch I forgot to flip somewhere....

memikri commented 3 years ago

You should be able to use it if you have a start script in your package.json, like:

"scripts": {
  "start": "node bot.js"
}

That would use the npm package node instead of the machine's node installation.

ghost commented 3 years ago

@Sly-Little-Fox

Then discord.js v13 will not work on replit

You still can install newer version of node in replit Simply type npm i node@14 in shell.. and enjoy! slightly_smiling_face

I just tested it- it doesn't look like that works- I still get an error thrown when I attempt to run a v13 bot. Looking at some comments online, it seems like Repl.it doesn't like other versions of Node... unless there's a glaring issue I've overlooked and the answer was a switch I forgot to flip somewhere....

Use Bash Repls as Replit staff say.

eunakria commented 3 years ago

As it stands, version 16.6.0 is extremely recent. You can't expect everyone to switch to it for Discord.js alone. For now, I'm temporarily using 12.x, but I would encourage you guys to start transpiling with Babel or similar if new JS features are that important to Discord.js.

kyranet commented 3 years ago

As it stands, version 16.6.0 is extremely recent. You can't expect everyone to switch to it

discord.js v13.0.0 is even more recent than node.js v16.6.0, I fail to see how is it more OK to install the former but not the latter if the time at which something released matters.

I would encourage you guys to start transpiling with Babel or similar if new JS features are that important to Discord.js.

To bump to v17-nightly he said.

No, seriously, we can't. It's not only about new syntax requirements, it's more about the node.js built-in features; we use globalThis.AbortController in our code (flagged in v14, unflagged since v15) and we promote the usage of timers/promises (available since node.js v16.0.0) and abort-able promise-based events (on and once from the events package) that otherwise need over 20 lines of advanced boilerplate code.

We'll probably use ??= soon, which is >=16.0.0, but we chose 16.6.0 minimum because it's a security release which also brings Array.prototype.at from the JS's side.


I hope this explains enough to you, again, it's not for JS features, it's for Node.js features, both inside (globalThis.AbortController) and outside (cancellable on + once).

iCrawl commented 3 years ago

you guys to start transpiling with Babel or similar if new JS features are that important to Discord.js.

You could use babel to transform certain node_modules yourself (it's really just a very simple pipeline) if it's that important that you run on old node versions ๐Ÿ‘

raymondfeng commented 3 years ago

IMO, mandating Node 16.6.0 or above really blocks a lot of applications from upgrading to the latest and greatest version of discord.js. For example, in my case, AWS Elastic BeanStalk only supports Node 12.x.

Fyko commented 3 years ago

@raymondfeng, while AWS doesn't yet support Node 16, you're still able to bundle whatever it is yourself with Docker. Additionally, you can always make your own layers, see this example for lambda.

raymondfeng commented 3 years ago

@Fyko Thank you for the pointer. I'm fully aware of such paths to use Node 16.x but most of them will have to change how applications are operated to some extent.

It's really boils down how we open source developers to strive to make users life easy.

  1. Project maintainers and contributors are eager to use latest and greatest syntax. I'm all for it!
  2. Users are keen on backward compatibility as much as possible.

I think the middle-ground is to use TypeScript or Babel and have a build step to produce JS code that is compatible with all LTS versions of Node, including 12.x.

It's not a big deal for my use case at the moment as we can stay with discord 12.x. Just want to chime in as an open source developer :-).

kyranet commented 3 years ago

AWS Elastic BeanStalk only supports Node 12.x.

Sounds like a bad hosting solution if you ask me, I can understand a service not supporting non-LTS versions, but I can't for a version that has been LTS for 10 months (v14).

I think the middle-ground is to use TypeScript or Babel and have a build step to produce JS code that is compatible with all LTS versions of Node, including 12.x.

It's not just language features, also Node.js features, please read the second half of https://github.com/discordjs/discord.js/issues/5119#issuecomment-894741632

And as Crawl suggested, you can use babel to transform certain dependencies (including discord.js) so they're supported in older versions of Node.js.

sachinraja commented 3 years ago

I don't think babel/core-js supports AbortController yet, so I don't think that will work. I tried transpiling with @babel/preset-env and targets set to node 12, but it still outputted the AbortController.

max-programming commented 3 years ago

I used replit and I can't change the version of Node.js in repl so I installed discord.js@12.5.3 and it worked. Yeah there won't be many new features but I am just starting to learn

sachinraja commented 3 years ago

This also won't work because @discordjs/rest uses timers/promises.

sachinraja commented 3 years ago

Ok, I've figured out a way to get it all working:

1: Install necessary packages on top of discord.js installs (npm i discord.js @discordjs/rest discord-api-types)

npm i abort-controller awaitable-timers patch-package

2: In the entrypoint for the client (this is usually index.js, where you use new Client), add this:

globalThis.AbortController = require('abort-controller').AbortController

This will polyfill AbortController with the abort-controller package.

3: Create a folder called patches and add a file called @discordjs+rest+0.1.0-canary.0.patch inside (this will change depending on your @discordjs/rest version). Copy this gist into it. If you are using a version other than 0.1.0-canary.0, go into the node_modules/@discordjs/rest/dist/lib/handlers/SequentialHandler.js file and change require("timers/promises") to require("awaitable-timers").

4: In package.json set scripts.postinstall to patch-package.

5: Run npm install.

Notes: Unfortunately, these steps will stop working once discord.js uses syntax only available in Node 16, but they should at least allow anyone on a lower Node version to upgrade to v13.

ImRodry commented 3 years ago

Discord.js already uses node 16 syntax such as nullish assignment and soon replaceAll and underscore as a numeric operator: #6540, just update seriously

sachinraja commented 3 years ago

6540 has not been merged yet. Why was my comment marked as off-topic? I'm trying to help people who cannot upgrade yet for whatever reason.

ImRodry commented 3 years ago

6540 has not been merged yet. Why was my comment marked as off-topic? I'm trying to help people who cannot upgrade yet for whatever reason.

Because your solution is not a solution like I said literally in the comment before yours

sachinraja commented 3 years ago

I tested my solution, it works. I would not have suggested it otherwise. I don't see any comments from you before my solution.

Also if my comment was off-topic, why did you copy the entire thing into your comment?

kyranet commented 3 years ago

I'm hiding them because they're in no way valid. We use ??= in @dev for REST's https.Agent, and more will follow, so there's no point for that.

Also, please do not post hacky workarounds, it's a lot easier to just update, whether that's via the website's installer, a package manager, nvm, npm, n, Docker, or whatever.

sachinraja commented 3 years ago

We use ??= in @dev for REST's https.Agent

If you're referring to this line: https://github.com/discordjs/discord.js/blob/29d5fd163c62ff03aa642f111972914fdeed3669/src/rest/APIRequest.js#L33 you're right but it was added after the 0.1.0-canary.0 release.

Also, please do not post hacky workarounds, it's a lot easier to just update

Alright, sorry about that. I thought it would be okay seeing as babel was recommended (but wouldn't work). Also not everyone is able to update (as outlined by others in this issue).

monbrey commented 3 years ago

you're right but it was added after the 0.1.0-canary.0 release.

Yes - but because this is v16.6 compatible which is what we declared the minimum version to be, we can introduce this in a semver compliant away that doesn't require a major release. People following our minimum versions will be unaffected, but the hacky workarounds will break.

sachinraja commented 3 years ago

but the hacky workarounds will break

They won't silently break because when you npm i @discordjs/rest it uses the pinned, exact version 0.1.0-canary.0. I get your point though.

ckohen commented 3 years ago

When did /rest get involved, that code you referenced is in the main library, which is still using its own rest implementation.

sachinraja commented 3 years ago

Ah that makes sense. I'm not exactly sure when that gets used though, but I was still able to get something with interactions working. Anyway, I won't discuss this any further.

x5engine commented 3 years ago

What a dumb move seriously!

I can't use the power of discord now and make my bot live because of this! When you choose the latest version of node

ImRodry commented 3 years ago

What a dumb move seriously!

I can't use the power of discord now and make my bot live because of this! When you choose the latest version of node

Why is that? Is it because you use a bad host?

x5engine commented 3 years ago

What a dumb move seriously! I can't use the power of discord now and make my bot live because of this! When you choose the latest version of node

Why is that? Is it because you use a bad host?

Sorry to be that guy but because i am restricted to nodejs 14 on firebase and they dont allow any new versions... I am gonna switch to v 12.5.3 now so i can use this on firebase. thanks but good work

ImRodry commented 3 years ago

The fact that you use a bad host is not the libraryโ€™s fault lol. It should be up to you to find a good one instead of rambling here

Dragonizedpizza commented 3 years ago

just change all file extensions to ts and compile to es5 lol

Deveroonie commented 2 years ago

Will there be any need for v17 in the future?

ImRodry commented 2 years ago

Probably not v17 but likely v18 on the next major release, once that hits LTS

ghost commented 2 years ago

Sorry to be that guy but because i am restricted to nodejs 14 on firebase and they dont allow any new versions... I am gonna switch to v 12.5.3 now so i can use this on firebase. thanks but good work

@x5engine There is actually a version of Discord.js v13 that supports node 14. It is discord.js@13.0.0-dev.t1628203362.f473f43

insyri commented 2 years ago

Will there be any need for v17 in the future?

As all things update, so will the requirements for everything; required node versions will likely be updated in parallel with time.

kyranet commented 2 years ago

No, we will never require an odd number (11, 13, 15, 17...) version of Node.js for the library to work. If the need arises, we will require latest LTS, even if it's a little ahead of time (like we did with v16.6.0).

We require 16.6.0 because it comes with a lot of new syntax that makes the library more maintainable, safer, and robust, which in turn results on improvements for everyone.

LukeSamkharadze commented 2 years ago

It's not improvement for everyone, for instance AWS Lambda function supports only Node 14 and to make this discord.js work with that we have to do some crazy parkour

kyranet commented 2 years ago

Then complain at your VPS provider for providing sub-par services. I fail to see why we shouldn't support LTS, specially when this version has been out for almost a year, and v16 reached LTS 3 months ago.

You're also free to change your VPS provider to one that doesn't needlessly restrict you to a specific ecosystem. Furthermore, the switch has allowed us to use syntax that makes the code cleaner and easier to maintain while also having better performance, so yes, I'd say that it's an improvement for the great majority.

By the way, starting with v14, we will require >=16.9.0, see the relevant PR at #7035.

LukeSamkharadze commented 2 years ago

If you want those new fancy JS syntaxes, use typescript or babel, both parties would be happy, you and the other developers who are blocked by this outrageous requirements

thehairy commented 2 years ago

If you want those new fancy JS syntaxes, use typescript or babel, both parties would be happy, you and the other developers who are blocked by this outrageous requirements

Stop living in 2015 and update or get a new hoster.

coldice commented 2 years ago

It's not improvement for everyone, for instance AWS Lambda function supports only Node 14 and to make this discord.js work with that we have to do some crazy parkour

It's coming for real now https://github.com/serverless/serverless/pull/11049