Time to test Node-RED with Bun again - It appears to be working!

May give it a go if I can find a bit of time.


Oh, weird - it took less time to install with powershell -c "irm bun.sh/install.ps1 | iex" than it did to start my PowerShell session!

Doh! Got my hopes up for a second there:

> bun start
$ bun node_modules/node-red/red.js --userDir ./data
4 Apr 14:50:20 - [info]

Welcome to Node-RED
===================

4 Apr 14:50:20 - [info] Node-RED version: v3.1.8
4 Apr 14:50:20 - [info] Node.js  version: v21.6.0
4 Apr 14:50:20 - [info] Windows_NT 10.0.22631 x64 LE
4 Apr 14:50:21 - [info] Loading palette nodes
4 Apr 14:50:22 - [info] Settings file  : D:\src\nrbun\data\settings.js
4 Apr 14:50:22 - [info] Context store  : 'default' [module=memory]
4 Apr 14:50:22 - [info] User directory : D:\src\nrbun\data
4 Apr 14:50:22 - [warn] Projects disabled : editorTheme.projects.enabled=false
4 Apr 14:50:22 - [info] Flows file     : D:\src\nrbun\data\flows.json
4 Apr 14:50:22 - [info] Creating new flow file
4 Apr 14:50:22 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

4 Apr 14:50:22 - [info] Server now running at http://127.0.0.1:1888/
4 Apr 14:50:22 - [warn] Encrypted credentials not found
4 Apr 14:50:22 - [info] Starting flows
4 Apr 14:50:22 - [info] Started flows

uh-oh: reached unreachable code
bun will crash now 😭😭😭

----- bun meta -----
Bun v1.1.0 (5903a614) Windows x64
AutoCommand: tsconfig(9) spawn transpiler_cache(12) http_server Bun.stdin(2)
Builtins: "bun:main" "detect-libc" "node:assert" "node:async_hooks" "node:buffer" "node:child_process" "node:constants" "node:crypto" "node:dns" "node:events" "node:fs" "node:http" "node:https" "node:module" "node:net" "node:os" "node:path" "node:process" "node:querystring" "node:stream" "node:string_decoder" "node:timers" "node:tls" "node:tty" "node:url" "node:util" "node:util/types" "node:vm" "node:zlib" "node:punycode" "ws" "node:http2" "node:dgram"
Elapsed: 38410ms | User: 390ms | Sys: 109ms
RSS: 0.27GB | Peak: 0.27GB | Commit: 0.35GB | Faults: 85464
----- bun meta -----

0   00007FF64CA0A4C8
1   ???
2   ???
3   ???
4   ???
5   ???
6   ???
7   ???
8   ???
9   ???
10  ???
11  ???
12  ???
13  ???
14  ???

Search GitHub issues https://bun.sh/issues or join in #windows channel in https://bun.sh/discord

thread 59784 panic: reached unreachable code
???:?:?: 0x7ff64b960ce1 in ??? (bun.exe)
???:?:?: 0x7ff64c3401f7 in ??? (bun.exe)
???:?:?: 0x7ff64c344946 in ??? (bun.exe)
???:?:?: 0x7ff64c34433f in ??? (bun.exe)
???:?:?: 0x7ff64b6d6db1 in ??? (bun.exe)
???:?:?: 0x7ff64db1caea in ??? (bun.exe)
???:?:?: 0x7ff64b64ea82 in ??? (bun.exe)
???:?:?: 0x7ff64b677d6a in ??? (bun.exe)
???:?:?: 0x7ff64b666154 in ??? (bun.exe)
???:?:?: 0x7ff64b391603 in ??? (bun.exe)
???:?:?: 0x7ff64dec7e33 in ??? (bun.exe)
???:?:?: 0x7ffbf5fe257c in ??? (KERNEL32.DLL)
???:?:?: 0x7ffbf810aa47 in ??? (ntdll.dll)
error: script "start" exited with code 3

Worth a try anyway. :grinning:

WAIT! I adjusted the jsconfig.json file to be more lenient and tried again.

This time I got the Editor up!!! :grinning: :sparkler:

And a simple flow works.

Yep, it is promising. I got it to run yesterday, ran simple inject->debug. It soon crashes (after a page refresh or running a userdir with a binary like sqlite or serial port)

My tests were far from extensive but its getting there :crossed_fingers:

image

So both MQTT (v5) and http-in/-out are working. That is very hopeful.

2 Likes

isn't uibuilder the acid test? :thinking:

You read my mind! :grinning:

-----------------------------------------------------------
2024-04-04T14:10:14.522Z Install : node-red-contrib-cron-plus 2.1.0

2024-04-04T14:10:14.540Z npm.cmd install --no-audit --no-update-notifier --no-fund --save --save-prefix=~ --production --engine-strict node-red-contrib-cron-plus@2.1.0
2024-04-04T14:10:15.481Z [err] npm
2024-04-04T14:10:15.482Z [err]  WARN config production Use `--omit=dev` instead.
2024-04-04T14:10:17.838Z [out] 
2024-04-04T14:10:17.838Z [out] added 7 packages in 2s
2024-04-04T14:10:17.848Z rc=0

-----------------------------------------------------------
2024-04-04T14:10:33.449Z Install : node-red-contrib-uibuilder 6.8.2

2024-04-04T14:10:33.470Z npm.cmd install --no-audit --no-update-notifier --no-fund --save --save-prefix=~ --production --engine-strict node-red-contrib-uibuilder@6.8.2
2024-04-04T14:10:34.365Z [err] npm
2024-04-04T14:10:34.371Z [err]  WARN config production Use `--omit=dev` instead.
2024-04-04T14:10:39.710Z [err] npm
2024-04-04T14:10:39.711Z [err]  WARN deprecated abab@2.0.6: Use your platform's native atob() and btoa() methods instead
2024-04-04T14:10:39.786Z [err] npm WARN
2024-04-04T14:10:39.794Z [err]  deprecated domexception@4.0.0: Use your platform's native DOMException instead
2024-04-04T14:10:40.898Z [out] 
2024-04-04T14:10:40.898Z [out] added 215 packages in 7s
2024-04-04T14:10:40.934Z rc=0

OK, good so far.

Yee-ha! :cowboy_hat_face:

Yes, UIBUILDER v6.8.2 appears to be working absolutely fine :grinning:


If you want to repeat the tests, this is what I did to install on Windows 11:

powershell -c "irm bun.sh/install.ps1 | iex"

mkdir nrbun
cd nrbun

echo " " > index.js # Force bun to use JS not TS
bun init -y

bun install node-red --production
bun pm trust --all # to get post-installs to run (for bcrypt)

In package.json, make sure to change the "type" to "commonjs".

Make some changes in jsconfig.json (not actually sure which of these are needed):

{
  "compilerOptions": {
    // Enable latest features
    "lib": ["ESNext", "DOM"],
    "target": "ESNext",
    "module": "ESNext",
    "moduleDetection": "force",
    "jsx": "react-jsx",
    "allowJs": true,

    // Bundler mode
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "verbatimModuleSyntax": true,
    "noEmit": false, // <== Changed from true to false

    // Best practices
    "strict": false, // <== Changed from true to false
    "skipLibCheck": true,
    "noFallthroughCasesInSwitch": false, // <== Changed from true to false

    // Some stricter flags (disabled by default)
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noPropertyAccessFromIndexSignature": false
  }
}
1 Like

You used npm install and not bun install :astonished: :wink:

Next: Try a binary like sqlite or serialport next (when I tried, i used an existing userDir and that is likely what crashed bun for me)

Ah, well that is Node-RED's "fault" - I used the Node-RED palette manager.

I'll try again manually with bun install. In theory, it should be mostly the same since bun is designed as a drop-in replacement for Node.js and npm anyway.


Cleared down and manually installed uibuilder with bun install node-red-contrib-uibuilder and it all worked. Tried one of the more complex uibuilder examples - the no-code examples - and it all works perfectly.

I can't really try serial on this dev PC. Let me try SQLite. If I can remember how to use it! Been a while.

Do note though that if using bun install, it doesn't run lifecycle scripts. So any package that requires a compile step (such as serial and sqlite), you need to make sure that they are added in advance to the package.json trustedDependencies list or that you run bun pm trust --all after installation.


Installed node-red-node-sqlite via the palette manager - that has worked fine. Can create db's & tables, insert and query data.

Installed sqlite-plugin-red which installed fine but fails to find a DLL when you use its sidebar panel - that might actually be a bug in how it handles Windows to be honest. I've never used it before.

TypeScript should also work out of the box, bun should run it, without even transpiling afaik.

I think you are right but Node-RED is mostly JS and I didn't want to make it harder - I honestly thought this would be difficult - but it isn't!!

One more test. I wanted to see if a function node could load a bun native module. It doesn't seem to work, I tried with bun:sqlite and it just ignored it. So I added

functionGlobalContext: {
    sqlite: require('bun:sqlite')
},

In settings.js and this worked like a charm!

const sqlite = global.get('sqlite');

const db = new sqlite.Database(":memory:");

db.run(`
  CREATE TABLE users (
    id INTEGER PRIMARY KEY,
    name TEXT
  );

  INSERT INTO users (name) VALUES ("Alice");
  INSERT INTO users (name) VALUES ("Bob");
`);

const query = db.query("select * from users;");
msg.payload = query.all();

return msg;

I'm really liking bun!

Now to try with my local dev version of uibuilder.


Hmm, there are clearly still some fragile bits of bun.

Trying to re-install uibuilder from the local dev version with it already installed:

> bun install /src/node-red-contrib-uibuilder
bun add v1.1.0 (5903a614)
error: Package "etag@1.8.1" has a dependency loop
  Resolution: "ignore@5.3.1"
  Dependency: "://registry.npmjs.org/node@^6.8.2"

Some advice from a similar issue in GitHub lead to me uninstalling first. That got me slightly further:

> bun remove node-red-contrib-uibuilder
bun remove v1.1.0 (5903a614)

 8 packages installed [1.87s]
  Removed: 1
D:\src\nrbun\data
> bun install /src/node-red-contrib-uibuilder --production
bun add v1.1.0 (5903a614)
error: lockfile had changes, but lockfile is frozen
note: try re-running without --frozen-lockfile and commit the updated lockfile

The error bears no resemblance to anything useful. Something to do with the --production flag.

Re-running again without the prod flag gave me this:

> bun install /src/node-red-contrib-uibuilder
bun add v1.1.0 (5903a614)

 installed node-red-contrib-uibuilder@../../../..//src/node-red-contrib-uibuilder

 591 packages installed [201.97s]

 Blocked 1 postinstall. Run `bun pm untrusted` for details.

Which worked but note that it took 202 seconds! Definitely something odd there. Even with the dev dependencies included, that is far too long. And I should be able to install without the dev dependencies!

However, it did eventually work - kind-of.