oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.12k stars 2.76k forks source link

PM2 doesnt with with Bun #4949

Open Meldiron opened 1 year ago

Meldiron commented 1 year ago

What version of Bun is running?

1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983

What platform is your computer?

Linux 5.15.49-linuxkit aarch64 unknown

What steps can reproduce the bug?

Create Dockerfile:

FROM oven/bun:1.0.0
RUN bun install --global pm2
RUN pm2 --help

You get: /bin/sh: 1: pm2: not found

So you try:

FROM oven/bun:1.0.0
RUN bun install --global pm2
RUN bunx --bun pm2 --help

What is the expected behavior?

Show version. Ultimate goal is to later do pm2 start --no-daemon 'bun src/server.ts'

What do you see instead?

error: SystemResources

----- bun meta -----
Bun v1.0.0 (822a00c4) Linux arm64 #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022
BunxCommand: 
Elapsed: 9ms | User: 0ms | Sys: 11ms
RSS: 33.55MB | Peak: 11.87MB | Commit: 33.55MB | Faults: 0
----- bun meta -----

0   0xaaaacd71f478
1   ???
2   ???
3   ???
4   ???
5   ???

Crash report saved to:
  ~/.bun-crash/v1.0.0-1694439849292.crash

Search GitHub issues https://bun.sh/issues or ask for #help in https://bun.sh/discord

Additional information

No response

CodeFromAnywhere commented 1 year ago

Related? https://github.com/oven-sh/bun/issues/4327

elendil7 commented 1 year ago

Can confirm, am experiencing the same issue.

vuongphamaioz commented 1 year ago

I run bun with pm2 successfully with this setup:

calebeaires commented 1 year ago

@vuongphamaioz, I did to, but got this error " errored " if we set -i 3 (multiple clusters)

vuongphamaioz commented 1 year ago

@calebeaires I just tried -i 3 and it worked. No errors occurred. pm2 start "bun my-ts-script.ts" -i 3 My script is simple, just an app that sends HTTP requests and interacts with DB.

calebeaires commented 1 year ago

@vuongphamaioz It were in Nuxt 3

Electroid commented 1 year ago

Thanks for reporting this issue, there are 2 issues here:

omt66 commented 1 year ago

I used this: pm2 start --interpreter bun src/server.ts Let me know if there is another way to test this.

calebeaires commented 1 year ago

Nothin different, when we start more than one cluster

CleanShot 2023-09-14 at 09 15 08@2x
milahnmartin commented 1 year ago

Any update on this issue ?

aaron-play commented 1 year ago

The only thing we are not using Bun in production is that we would like to take advantage of multi-core. We are actually indifferent between using pm2 and cluster module. We have been testing out different approaches on docker but it doesn't seem stable enough to be on production. It would be great if one of these could be prioritized.

The link to cluster module issue: https://github.com/oven-sh/bun/issues/2428

lostintheway commented 1 year ago

any way to serve using bun

pm2 serve -s build 3000 --spa

like this?

sancho1952007 commented 11 months ago

Nothin different, when we start more than one cluster

CleanShot 2023-09-14 at 09 15 08@2x

I am facing the exact issue!!! I am using Elysia in one of my production website but am facaing this issue please help us with this issue! I think it isn't fully supported for ElysiaJS. How can I get around this?

I think it isn't assigning the ports properly because of bun being a new framework!

PM2 Logs:

2|index    | EADDRINUSE: Failed to start server. Is port 8080 in use?
2|index    |  syscall: "listen"
2|index    | 
2|index    |       at /home/<REDACTED>/node_modules/elysia/dist/bun/index.js:316:40188
2|index    |       at /home/<REDACTED>/src/index.js:62:1
aaron-play commented 11 months ago

@sancho1952007 try this

new Elysia({ serve: { reusePort: true } })
sancho1952007 commented 11 months ago

@sancho1952007 try this

new Elysia({ serve: { reusePort: true } })

Thanks, I'll try it later!

toshirot commented 10 months ago

bun i -g pm2 bun pm2 start "bun app.js"

By the way, is "bun pm2 start app.js" "node app.js"? Or is it "bun app.js"?

Electroid commented 9 months ago

Both of the issues have been fixed:

If you're still experiencing issues with pm2, please open another issue with the error.

tapz commented 8 months ago

For me it looks like pm2 does not support bun anymore and ignores the interpreter flag completely:

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

.bun/bin/pm2 start --interpreter bun index.js

Abhid14 commented 8 months ago

Same issue here

mrctrifork commented 7 months ago

For me it looks like pm2 does not support bun anymore and ignores the interpreter flag completely:

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

.bun/bin/pm2 start --interpreter bun index.js

The interpreter flag only affects at the binary that is going to execute your index.js.

The problem you're facing (and myself; because I ended up here :) ) is that the pm2 script relies on node.

$: cat $(which pm2)
#!/usr/bin/env node

require('../lib/binaries/CLI.js');
$: 

Usually bunx --bun pm2 ...args should address this. In my machine this results in some prints to the console but no daemons spawned.


To work around this I have installed node in my machine and use pm2 with node and have my apps running with bun. Ideally this shouldnt be necessary

ironydips commented 6 months ago

Any update on this issue?

Pm2 -i 3 --interpreter=bun runs instances in FORK mode instead of Cluster mode.

Bun version: 1.1.6

marvinkennis commented 4 months ago

Would also like to know if there is an update here. No success with any of the above approaches.

paulGeoghegan commented 4 months ago

Same here. I have to install Node in order to use pm2 at all.

sindelio commented 2 months ago

For now I'm installing Node to use pm2 as well

harryqt commented 1 month ago

Related: https://github.com/Unitech/pm2/issues/5893

jim-king-2000 commented 1 month ago

I tried pm2.json5 config file:

{
    name: 'device_log',
    script: 'bun',
    args: '--bun run start',
    interpreter: '/root/.bun/bin/bun',
    exec_mode: 'fork',
    instances: 1,
    env: {
        NODE_ENV: 'production',
    },
}

But the program fails. How could we run bun --bun run start in PM2 config file?

OrPh4ns commented 1 month ago

I run bun with pm2 successfully with this setup:

* Ubuntu 20

* Install bun by `npm i -g bun`, node 18, `bun v1.0.0`

* Install pm2 by `npm i -g pm2`

* Run by `pm2 start "bun my-ts-script.ts"`
  Hope it helps!

npm needs nods js

how to do it only with bun

mario-huang commented 1 month ago

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

eliot-akira commented 2 weeks ago

I was getting the same error as @tapz when running pm2 with Bun.

$ bun add --global pm2@latest

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

$ head $(which pm2) -n 1
#!/usr/bin/env node

Instead of installing Node.js, I was able to solve it by creating a symlink named node to run bun.

$ which bun
/home/ubuntu/.bun/bin/bun

$ cd ~/bin
$ ln -s ~/.bun/bin/bun node

The above assumes that the directory ~/bin exists and is in your $PATH. For example, defined in ~/.bashrc.

export PATH=$HOME/bin:$PATH
miaobuao commented 1 week ago

I use WSL2, and its ok. Looks like it would only be a problem on windows?

harryqt commented 1 week ago

It is now fixed at dev branch

eliot-akira commented 1 week ago

Nice solution in pm2.

# Check if 'bun' is available, otherwise use 'node'
if command -v bun &> /dev/null
then
    bun "$SCRIPT_PATH" "$@"
else
    node "$SCRIPT_PATH" "$@"
fi