nodejs / node

Node.js JavaScript runtime βœ¨πŸ’πŸš€βœ¨
https://nodejs.org
Other
106.42k stars 29k forks source link

Implement "Real" Single executable applications, which contains only the modules actually used #53476

Open toviszsolt opened 2 months ago

toviszsolt commented 2 months ago

What is the problem this feature will solve?

It opens a new chapter in the history of Nodejs, and unlocks the true potential for developing CLI applications. There is a dire need for a "real" solution among developers. Unfortunately, "Single executable applications" is not a real solution.

What is the feature you are proposing to solve the problem?

Instead of copying the node.exe and appending a blob file to it, go ahead and implement it properly, as it should be. The "Hello World" executable should take KBs instead of 67MB. Instead of embedding the whole node.exe, only the modules that are actually used should be included in the executable.

What alternatives have you considered?

No response

RedYetiDev commented 2 months ago

Duplicate of https://github.com/nodejs/node/issues/51928

toviszsolt commented 2 months ago

@RedYetiDev

Please don't mark it as a duplicate, because I'm not talking about the build of nodejs itself, but about the packaging of JavaScript applications running on Nodejs.

You so quickly closed this issue that I had no chance to respond immediately. Don't do this! So the two issues have nothing to do with each other. I don't have a problem with the size of Nodejs alone, it's fine. You misunderstood what I wrote, or I didn't make it clear enough.

Vercel has terminated the maintenance of the pkg, referring to you, literally: Further, we’re excited about Node.js 21’s support for single executable applications.

So I am talking about the support for "single executable applications" added to Node v20.

RedYetiDev commented 2 months ago

Sorry, I should've clarified why I chose what I chose.

I believe this is a duplicate, not because they are similar in question, but because they are similar in solution.

To implement a way for the SEA programs to be modular, one would need to modularize the internals, which is what the other issue was discussing.

If a member of the team disagrees, they can always re-open this issue, and I'm sorry in advance if I misjudging the request.

@nodejs/single-executable

toviszsolt commented 2 months ago

@RedYetiDev

Now I understand, no problem. I saw that you started a new issue with a nicely organized proposal. I wrote +1 there. And I feel the situation, don't worry. And thank you for your reply and for your time.

RedYetiDev commented 2 months ago

@anonrig is there a reason for the reopen?

anonrig commented 2 months ago

@anonrig is there a reason for the reopen?

I like to understand what the proposed solution is.

toviszsolt commented 2 months ago

@anonrig

Well, since you've reopened it, I'd like to add a few words. 😁 So the suggestion would be not to use the installed node binary to produce the executable, but a cleaned up, lightweight build. This "single executable app" doesn't need to contain a lot of stuff, because we can be 100% sure that it will 1) be production only 2) nobody will touch it, because it's impossible (it's a binary).

I found an older forum here where back in 2014 they succeeded in reducing the V8 build to 2.8MB. This Louis Santillan seems like a big shrinker. https://groups.google.com/g/v8-users/c/OaC4TQQjxFg

And now let me talk a little bit about the why: There are millions of tiny, micro apps running on node around the world. Most of these are usually less than 200 lines of js code. However, as insignificant as they may seem, they are just as important in our modern lives.

Most of these small pieces of code perform CI/CD tasks or run as a system service, either in a docker container or as a background service. If these millions of tiny codes were not running, a lot of things in the world would stop and a lot of phones would ring.

The other side of the coin is Electron. More and more great applications are being built on Electron, where the minimum size of the application depends on the size of the node. VSCode, Messenger, Slack, Discord, Figma, Signal, Skype, Teams, just to mention a few. One thing these apps have in common is that the smallest size is usually 150MB, but 300-400MB is more common and so they eat up memory.

So here's why. Which is why you threw out the unnecessary stuff from alpine, to reduce the size of the node-apline docker image. If you have a script that is only 2KB, why make it almost 100MB binary if you don't have to?

As I wrote earlier, I have no problem with the size of the installed node, in fact it is more than perfect, you have done a nice job with it.

Well, I am very curious to hear your views on what has been written. πŸ™ƒ