pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

migrate to bun

Open Mrgaton opened this issue 1 year ago • 16 comments

pm2 logs uses 30% of resources of my machine, im using it on a potato but a bun version would be great

Mrgaton avatar Feb 23 '24 19:02 Mrgaton

You want to use bun as interpreter?

pm2 start --interpreter ~/.bun/bin/bun

ultimate-tester avatar Feb 29 '24 08:02 ultimate-tester

Won't be nice to make that as default?

I don't see any disadvantage of not using bun

Mrgaton avatar Feb 29 '24 10:02 Mrgaton

It won't be as easy as just stating "let's make a different interpreter the default". Here's some cons just for sake of argument:

  • Bun is still under development.
  • Bun is not as widely used as Node.js.
  • Bun does not support all Node.js APIs.
  • Bun is not as well-documented as Node.js.

So, while Node.js is still the most popular, complete and stable production-ready interpreter, in my opinion PM2 should stick with it and only start discussing about it when Node.js is surpassed in those areas.

Nothing against Bun, but you have to be realistic.

ultimate-tester avatar Feb 29 '24 10:02 ultimate-tester

You want to use bun as interpreter?

pm2 start --interpreter ~/.bun/bin/bun

how i can make it permament and then how i can leave it as default?

Mrgaton avatar Feb 29 '24 14:02 Mrgaton

Actually coming back to this, it seems that bun is the default already for typescript (bad decision if you ask me) since oct 6 2023: https://github.com/Unitech/pm2/commit/135c123adcb207f9c544bcc6c6853c3f8488fb31

That would mean that if you really want to use bun by default, either modify that file manually or use typescript extension.

ultimate-tester avatar Feb 29 '24 15:02 ultimate-tester

I can't get pm2 to work with bun at all. Whatever I do pm2 always gives this error:

/usr/bin/env: 'node': No such file or directory

I have tried with command line arguments and with a configuration file. Still it seems to ignore the interpreter argument completely.

.bun/bin/pm2 start ecosystem.json .bun/bin/pm2 start --interpreter bun index.js .bun/bin/pm2 start --interpreter /usr/local/bin/bun index.js

ecosystem.json:

{
  "apps": [
    {
      "name": "myapp",
      "script": "index.js",
      "interpreter": "/usr/local/bin/bun",
      "instances": 1,
      "exec_mode": "fork",
      "autorestart": true,
      "watch": false,
      "error_file": "./errors.log",
      "out_file": "./myapp.log"
    }
  ]
}

tapz avatar Mar 07 '24 11:03 tapz

You can run it with bun --bun pm2 start. This will run bun instead of node, however, you'll immediately hit the next problem: cluster mode is not yet implemented in bun and pm2 tries to use that. Which will throw an error and exit.


Later edit: bun 1.1.25 has added support for cluster mode so the command above seems to be working now 💥

terebentina avatar Aug 01 '24 05:08 terebentina

But it doesn't on work on ts bun files, it still shows:

Failed to load Typescript interpreter: Cannot find module 'ts-node/register'

mavyfaby avatar Aug 22 '24 00:08 mavyfaby

cluster mode is not yet implemented in bun

Not anymore. See: https://bun.sh/blog/bun-v1.1.25#node-cluster-support

harryqt avatar Sep 18 '24 00:09 harryqt

i think we should migrate to run always in bun by default if installed

PayasoConEstilo avatar Sep 18 '24 11:09 PayasoConEstilo

Hi all, I find a workaround. https://github.com/Unitech/pm2/issues/5893#issuecomment-2395029376

mario-huang avatar Oct 05 '24 11:10 mario-huang