Bun 1.0 released! SVR.JS can run on it! (at least partially)

Bun 1.0 released! SVR.JS can run on it! (at least partially)

Bun - a Node.JS-compatible JavaScript runtime (using JavaScriptCore), package manager, bundler, test runner and all-in-one toolkit has finally a production-ready version - Bun 1.0!

We did get SVR.JS working in Bun, beginning with SVR.JS 3.0.0. But Bun changed fast, and so older SVR.JS versions won’t work properly with newest versions of Bun. We have tested Bun 1.0 (it introduced native IPC not present in Bun 0.x), patched SVR.JS and released SVR.JS 3.9.4 and SVR.JS 3.4.32 LTS (older versions displayed TypeErrors with Bun 1.0).

Bun support is still experimental though, so you may run into problems with SVR.JS startup (“There was an unknown error with the server.“ errors; master will shut down but worker will be active) or see “There was a problem when handling SVR.JS worker! (from master process side)“ warnings, because Bun doesn’t support native clustering yet (SVR.JS shims missing cluster module; the shim may break with newer versions of Bun making SVR.JS reliability suffer).

If you run into issues running SVR.JS on Bun 1.0, try using Bun 0.8.1 (latest developement version; it works with clustered SVR.JS and it’s shim) or Node.JS (SVR.JS is designed for it).

You may also create this startup script for SVR.JS running on Bun 1.0 like this (multiple clustering will not work on SVR.JS running on Bun 1.0, so SVR.JS will fail to start new worker in case the previous ones hung up, but SVR.JS will at least start new worker in case if all of the workers had crashed):

1
2
3
4
5
#!/bin/bash
while ! bun svr.js; do
echo "Restarting SVR.JS, because it crashed/failed to start..."
pkill -9 -f 'bun .*svr\.js'
done

It is also possible to run SVR.JS single-threaded on Bun 1.0, although reliability of SVR.JS may suffer. For that, you can create this startup script:

1
2
3
4
#!/bin/bash
while ! bun svr.js --single-threaded; do
echo "Restarting SVR.JS, because it crashed/failed to start..."
done

Here are screenshots of SVR.JS running on Bun 1.0:

Console of SVR.JS running on Bun 1.0
Default server page served by SVR.JS running on Bun 1.0
404 Not Found page generated by SVR.JS running on Bun 1.0

Maybe we will replace Node.JS with Bun on our own servers, when Bun begins to support clustering and maybe HTTP/2…

UPDATE: SVR.JS 3.10.0, SVR.JS 3.4.35 LTS and newer has limited the number of workers on Bun 1.0 with shimmed (not native) cluster module to one, because of above mentioned problems.