I am looking for the best practice to import an ES6 module in a node for Node-Red. I would appreciate it if someone can provide me with some guidance here.
Here is some additional background information:
There is an library on Github which has recently been upgraded and repackaged as an ES6 module: ibmtjbot/tjbotlib/releases (Release 2.0.1)
And this repository is hosting a project with Node-Red nodes making use of an older release of the above mentioned library (Release 1.5.1):
jeancarl/node-red-contrib-tjbot
The problem I am running into is that the Node-Red nodes are CommonJS nodes. And the updated library is now an ES6 module. The best explanation I have found so far why this is troublesome: https://redfin.engineering/node-modules-at-war-why-commonjs-and-es-modules-cant-get-along-9617135eeca1
So my question is, what is the best and most efficient approach here to make things compatible again?
-
Defining the Node-Red Nodes as "type": "module" in it's package.json and work from there? I have tried this, but this will result into all the .js files being treated as a ES modules. And from what I have seen the Node-Red loader script is a CommonJS module, so not able to import the ES modules either.
And if I rename them to .cjs files, they are not being picked up by the Node-Red loader script (/usr/local/lib/node_modules/node-red/node_modules/@node-red/registry/lib/loader.js). -
Looking into how to create a "Dual Package" of the library currently packaged as an ES6 module to support both CJS as well as ESM?
Or is there maybe another option I am missing?