bun icon indicating copy to clipboard operation
bun copied to clipboard

PM2 doesnt with with Bun

Open Meldiron opened this issue 2 years ago • 23 comments

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

Meldiron avatar Sep 11 '23 13:09 Meldiron

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

janwilmake avatar Sep 11 '23 15:09 janwilmake

Can confirm, am experiencing the same issue.

elendil7 avatar Sep 12 '23 00:09 elendil7

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!

vuongphamaioz avatar Sep 12 '23 07:09 vuongphamaioz

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

calebeaires avatar Sep 12 '23 19:09 calebeaires

@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.

vuongphamaioz avatar Sep 13 '23 02:09 vuongphamaioz

@vuongphamaioz It were in Nuxt 3

calebeaires avatar Sep 13 '23 11:09 calebeaires

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

  • #4738
  • #4785

Electroid avatar Sep 13 '23 20:09 Electroid

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

omt66 avatar Sep 13 '23 23:09 omt66

Nothin different, when we start more than one cluster

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

calebeaires avatar Sep 14 '23 12:09 calebeaires

Any update on this issue ?

milahnmartin avatar Oct 03 '23 16:10 milahnmartin

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

aaron-play avatar Oct 06 '23 01:10 aaron-play

any way to serve using bun

pm2 serve -s build 3000 --spa

like this?

lostintheway avatar Oct 16 '23 09:10 lostintheway

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

sancho1952007 avatar Dec 04 '23 17:12 sancho1952007

@sancho1952007 try this

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

aaron-play avatar Dec 06 '23 11:12 aaron-play

@sancho1952007 try this

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

Thanks, I'll try it later!

sancho1952007 avatar Dec 06 '23 11:12 sancho1952007

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"?

toshirot avatar Dec 15 '23 22:12 toshirot

Both of the issues have been fixed:

  • https://github.com/oven-sh/bun/issues/4738
  • https://github.com/oven-sh/bun/issues/4785

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

Electroid avatar Feb 06 '24 18:02 Electroid

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

tapz avatar Mar 07 '24 11:03 tapz

Same issue here

Abhid14 avatar Mar 11 '24 07:03 Abhid14

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

mrctrifork avatar Mar 15 '24 15:03 mrctrifork

Any update on this issue?

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

Bun version: 1.1.6

ironydips avatar Apr 28 '24 13:04 ironydips

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

marvinkennis avatar Jun 14 '24 23:06 marvinkennis

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

paulGeoghegan avatar Jun 28 '24 13:06 paulGeoghegan

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

sindelio avatar Aug 14 '24 13:08 sindelio

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

harryqt avatar Sep 18 '24 10:09 harryqt

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?

jim-king-2000 avatar Sep 23 '24 09:09 jim-king-2000

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

OrPh4ns avatar Sep 25 '24 07:09 OrPh4ns

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

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

eliot-akira avatar Oct 20 '24 23:10 eliot-akira

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

miaobuao avatar Oct 24 '24 16:10 miaobuao