Hi, is there a way to make a type module project work with Node-RED? I tried it and I will get the following error once I start Node-RED:
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/hallownest/Repositories/node-red-project/src/my-node.js from /Users/hallownest/.npm-packages/lib/node_modules/node-red/node_modules/@node-red/registry/lib/loader.js not supported.
It's also worth noting that one of the dependencies I use only supports ESM, so I am pressed to be ESM as well, unless I want to do hacky changes to accommodate it (dynamic imports).
I do think that someone posted an example of using ES modules with Node-RED some time last year. It appeared to be possible. It is certainly possible for the Editor and I've already started to convert my main package. Not so sure about converting the runtime but I remember that the example showed that.
As for loading ES modules as dependencies, as long as you are using newer versions of node.js (as you should now be), you can load ES module dependencies. But obviously, if your own runtime code is not an ES module then you have to load the ES Modules using the async version of import()
. You cannot require
them.
1 Like