🤷 Node-RED v5 now supports ESM nodes! MAYBE? Maybe not

Just in case you missed this. The following PR was incorporated in v5.

A big step forward for the future of Node-RED. :smiley:

I've already migrated everything I could in UIBUILDER to ESM but now I can start migrating the runtimes as well.

So, I attempted to migrate my inline-debug node to ESM.

You can check out both the CommonJS and the ESM versions in the repo above.

The ESM version fails and I cannot work out why or how. If I swap to the ESM version, I get no errors in the node-red log nor in the Editor and the node instance code executes, I can show the node data in the log, but ... the Editor shows the node as "Unknown".

I have no way of tracking down why this is happening. I've tried doing debug traces but nothing shows up.

I anyone has any ideas as to why or how I can find the problem, please do let me know.

Sadly, until this can be worked out, I cannot recommend that anyone tries to migrate a node's runtime to ESM.

I also cannot recommend anyone tries to load a node's Editor code as an ESM resource either since that also does not work correctly (see the other thread on that subject).

Annoyingly, this means that we are still stuck in CommonJS land.

You might want to check this out... ESM Version --> ESM version ?

Sorry, I don't understand?

Changing ESM Version to ESM Version?

I think it might be semantics re-reading a couple of times.

We know that Node-RED is able to work with ESM nodes, based on the work Alan did with his nrg node generator. That was all ESM based and worked in NR4, let alone NR5.

I don't know the specifics, but he clearly found a way to solve some of the issues you've hit.

I don't have hands-on experience of building with ESM, so can't really suggest anything. Ideally we'd be able to step through what is/isn't working for you and figure out how to get it working. I suspect there will be some constraints, or specific patterns needed. If someone is able to figure those out, then we can add documentation around it - including the fact nrg exists as an option to use.

Thanks Nick. Sorry if that previous post came across as a bit of a whinge, it was a frustrating day.

Appreciate that the complexity of Node-RED may well surface some things that need to be worked around. My problem really is that I can't find a way to debug the issue. Clearly it sometimes works but the Editor colour issue is pretty repeatable. The runtime issue is harder to analyse because I'm not seeing any errors other than the node showing up as Unknown in the Editor.

Is there any place in the core that I could find out why the node's instance function is clearly running but the the Editor shows it as unknown? If I can get a clue as to where to look, I can start to debug more intelligently.

I'm guessing that the colour issue is a timing edge-case but the runtime issue, I've no place to start I'm afraid.