44 lines
2.8 KiB
Markdown
44 lines
2.8 KiB
Markdown
|
---
|
||
|
title: Bun 1.0 released! SVR.JS can run on it! (at least partially)
|
||
|
date: 2023-09-08 21:36:33
|
||
|
tags:
|
||
|
- bun
|
||
|
- node.js
|
||
|
categories: News
|
||
|
---
|
||
|
|
||
|
**[Bun](https://bun.sh)** - 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](https://bun.sh/blog/bun-v1.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** <!--<s>**SVR.JS 3.9.6**</s> and **SVR.JS 3.4.34 LTS**--> (older versions displayed *TypeError*s 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](https://github.com/oven-sh/bun/issues/2428) (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):
|
||
|
```bash
|
||
|
#!/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:
|
||
|
```bash
|
||
|
#!/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](/images/svrjs-on-bun-console.png)
|
||
|
![Default server page served by SVR.JS running on Bun 1.0](/images/svrjs-on-bun-startpage.png)
|
||
|
![404 Not Found page generated by SVR.JS running on Bun 1.0](/images/svrjs-on-bun-404.png)
|
||
|
|
||
|
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.
|