Repository navigation
Add support for installing ESM module nodes - #4355
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. |
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 |
431ab4e to
0d20157
Compare
|
@hlovdal realise I missed this for today's beta. My apologies - it's now on my radar to make sure we get it done before final 5.0 release. |
There was a problem hiding this comment.
Pull request overview
This PR updates the Node-RED registry loader to support loading nodes implemented as ES modules (ESM), addressing installation/runtime failures caused by attempting to require() ESM node entrypoints.
Changes:
- Switch node runtime loading from
require()to dynamicimport()using afile://URL to support ESM node entry files. - Preserve existing interop behaviors (default export /
__esModulehandling) when loading modules. - Update a unit test assertion to match the new error formatting behavior.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
packages/node_modules/@node-red/registry/lib/loader.js |
Reworks node loading to use dynamic import() (ESM-compatible) and refactors the promise flow; includes some cleanup and added explanatory notes. |
test/unit/@node-red/registry/lib/loader_spec.js |
Adjusts expected error string for a node-load failure case to match the new import-based behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No variable renames, just lines moved.
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).
0d20157 to
0997721
Compare
|
@hlovdal thank you for your patience. This will be in NR5. |
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