pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

Bun Interpreter Not Working on Latest PM2 Version

Open BurkeDesigns opened this issue 9 months ago • 3 comments

I have installed the following:

  • NVM version 0.40.1
  • Node version 23.10.0 installed at "/home/wesley/.nvm/versions/node/v23.10.0/bin/node"
  • PM2 version 6.0.5 installed at "/home/wesley/.nvm/versions/node/v23.10.0/bin/pm2"
  • Bun version 1.2.5 installed at "/home/wesley/.bun/bin/bun"

I am unable to run PM2 using Bun as the interpreter even when I specify the install location of Bun. PM2 shows it as running, but when I try to access the API application, it does not work. When I use Bun directly, it works. This problem has only occured since I upgraded to use the new version of PM2 (version 6.0.5). Examples below I have tried:

  • pm2 start ./index.ts --name "api" --interpreter bun - NOT WORKING
  • pm2 start ./index.ts --name "api" --interpreter /home/wesley/.bun/bin/bun - NOT WORKING
  • pm2 start ./index.ts --name "api" --interpreter=/home/wesley/.bun/bin/bun - NOT WORKING

The only command that does work is the following, however I don't know if this will prevent PM2's auto restarts for errors:

  • pm2 start "bun run ./index.ts" --name "api"

BurkeDesigns avatar Mar 21 '25 18:03 BurkeDesigns

Issue First

If PM2 isn’t properly handling --interpreter, you can directly invoke Bun with pm2 start by passing the full command as follows:

pm2 start "bun run ./index.ts" --name "api"

This should work as you indicated that it works but you’re concerned about auto-restarts. Don’t worry, PM2 does support automatic restarts even if the command includes a bun run wrapper.

To ensure it restarts on errors, you can use this flag:

 pm2 start "bun run ./index.ts" --name "api" --watch

The --watch flag will make PM2 restart the process on file changes or crashes.

Image

You can see in this image where enabled is written in the watching column.

Issue Second May be possible that the bun is not propperly installed or added in the $PATH and for that

First Verify that the bun in installed by

bun --version

if it is not installed then install it using following command

curl -fsSL https://bun.sh/install | bash

[Note:- To install bun using non root user and you can use sudo if need extra permission.]

This will automatically install Bun and place it in your ~/.bun/bin directory. After installation, add it to your PATH

To add it to your PATH, run:

echo 'export PATH="$HOME/.bun/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Then try running

bun --version

After that you can run the app using the commands you are trying to run

pm2 start ./index.ts --name "api" --interpreter bun
pm2 start ./index.ts --name "api" --interpreter /home/username/.bun/bin/bun
pm2 start ./index.ts --name "api" --interpreter=/home/username/.bun/bin/bun

rohankamble103 avatar Apr 08 '25 13:04 rohankamble103

Still same in release 6.0.8 doesn't works even if you specify absolute binary path

cc @Unitech

neo773 avatar Jun 21 '25 20:06 neo773

5.3.0 works, 6.0.8 doesn't. Tried many thing to remove completely old version, no help.

sbscan avatar Jul 12 '25 14:07 sbscan