Add support for installing ESM module nodes#4355
Add support for installing ESM module nodes#4355hlovdal wants to merge 6 commits intonode-red:devfrom
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
66af0c2 to
7f8730a
Compare
This comment was marked as outdated.
This comment was marked as outdated.
468bdaf to
393658c
Compare
fbuys
left a comment
There was a problem hiding this comment.
I am excited for this to be released, I left a comment if it helps.
393658c to
97a5fda
Compare
|
The original branch before the rebase is saved in my repo as |
97a5fda to
c4f6268
Compare
|
Argh, the stupid update branch button has a default action to merge dev if you miss the drop down indicator on the side by a few pixels. Of course I intended to rebase. I'll fix it manually with a force push. |
2bf0fde to
f8cbcb5
Compare
368d6f0 to
fb71032
Compare
|
Can you please merge this pull request? It is 2026 and ESM is undeniably the future of javascript, and it has already been for a very, very, very long time. By not supporting nodes in ESM format node-red is preventing the world from progressing. While ESM support slowly is adapted for And even with the new esm support for require, merging this into V5 later will reduce version differences, and I would expect future undiscovered issues related to require(esm) to be much more probable than standard dynamic import which has been stable for years. But if you want this to stop in V4 and just rely on the behaviour of the runtime, that is a viable option. But for V4 this is an absolute must have functionality. The branch is rebased to the latest V4 version and is now fully up to date. For testing you can use my lowercase ESM node. Or compile yourself from the |
|
I am also very much looking forward to this, hopefully it will get merged soon... 2.5 years and not much happened so far... :( |
|
There is an issue with the code I'm afraid. It will not work on Windows because const { pathToFileURL } = require('node:url');
// ....
// let importPromise = import(node.file);
const modulePath = pathToFileURL(node.file).href;
let importPromise = import(modulePath); |
|
@TotallyInformation Thank you for reporting. I will look into that (although possibly not immediately the first few days). |
20c1e3e to
2bb7d82
Compare
a076a44 to
a881659
Compare
|
The windows issue has been fixed for a while. On my node-red node in typescript repo I have set up automatic tests for full end-2-end tests with Cypress, installing and testing an esm node on a node-red instance build from the For now the windows runner times out because @TotallyInformation Do you want to be the author of the commit that fixes the import? It is basically identical with your comment. |
No, that's fine. Thanks for the offer though. |
Absolute file paths cannot be used on windows, and strictly speaking using urls is the correct approach even if paths might work, nodejs/node#34765 (comment).
a881659 to
c6c244b
Compare
|
All commits pass after the latest rebase. git test add -t test "npm ci && npm run test"
git test run -t test dev..installing_esm_nodes |
Proposed changes
Currently node-red fails when attempting to install a node written as an ESM module, e.g.
This pull request fixes that by using dynamic
import()instead ofrequire.Checklist
npm run testto verify the unit tests pass