Repository navigation
Description
Current Behavior
#5220 asked for the editor template path to be derived correctly for non-.js entry points:
The loader should be able to load both nodes and plugins having a file name
*.cjs(and possibly also*.mjs).
#5221 applied the .cjs half. In 5.0.4, loadNodeConfig() still reads:
// packages/node_modules/@node-red/registry/lib/loader.js
template: file.replace(/\.c?js$/, ".html"),That leftover matters now that #4355 has shipped: loadNodeSet() loads entry points via dynamic import(), so an ESM node works at runtime, but for sample.mjs the substitution is a no-op and node.template points at sample.mjs itself. loadNodeTemplate() then reads the JavaScript source as the node's HTML — no ENOENT, no data-template-name match, types: [], and the source is shipped to the editor as node.config.
Net effect, with nothing logged:
- the node registers server-side and is listed in Palette Manager;
RED.nodes.getType('sample')isundefinedin the editor;- the node is absent from the palette, and shows as Unknown in any flow using it.
Renaming to sample.cjs with module.exports = makes it appear normally.
Two notes:
.js+"type": "module"is not a sufficient answer: a package that is CommonJS overall can only make a single node an ES module via.mjs, which is the incremental-migration path Add support for installing ESM module nodes #4355 opens up.loadPluginConfig(), ~20 lines below, already uses the extension-agnosticfile.replace(/\.[^.]+$/, ".html").
This is also a plausible cause for the unexplained ESM failure in https://discourse.nodered.org/t/node-red-v5-now-supports-esm-nodes-maybe-maybe-not/101259.
Suggested fix — align with loadPluginConfig():
template: file.replace(/\.[^.]+$/, ".html"),Or narrowly, /\.[cm]?js$/. The generic form additionally covers .ts entry points at no cost: Node strips types natively as of 22.6 (unflagged since 23.6), so import() already loads them and the template derivation is the only thing standing in the way — no transpiler, no dependency, no TypeScript support commitment on Node-RED's part.
Workaround meanwhile — a .js shim as the declared entry point:
export { default } from './sample.mjs';Expected Behavior
An ESM node entry point should have its .html located the same way a CommonJS one does, so that a node declared as *.mjs is usable in the editor and not just at runtime.
Steps To Reproduce
Package with no "type" field and "node-red": { "nodes": { "sample": "sample.mjs" } }.
sample.mjs
export default function (RED) {
function SampleNode(config) {
RED.nodes.createNode(this, config);
}
RED.nodes.registerType('sample', SampleNode);
}sample.html — a standard editor registration for type sample with a data-template-name="sample" block.
- Install the package into
.node-redand start Node-RED. - The startup log is clean — no error, no warning.
- Settings → Palette → Nodes: the module and its
samplenode are listed. - The palette does not contain the node.
- In the editor console,
RED.nodes.getType('sample')returnsundefined.
The same happens with a .ts entry point, which is the case I actually hit and verified — Node 24 strips types natively with no flag and import() loads the file unchanged, so from the loader's point of view it is just another extension that /\.c?js$/ doesn't match:
"type": "module",
"node-red": { "nodes": { "sample": "sample.ts" } }import type { NodeAPI, Node, NodeDef } from 'node-red';
export default function (RED: NodeAPI) {
function SampleNode(this: Node, config: NodeDef) {
RED.nodes.createNode(this, config);
}
RED.nodes.registerType('sample', SampleNode);
}Identical outcome: initialize runs, registerType succeeds, RED.nodes.getType('sample') is undefined, nothing logged.
Example flow
N/A — the node never reaches the palette, so no flow can be built with it.
Environment
- Node-RED version: 5.0.4
- Node.js version: 24.19.0
- npm version: 11.17.0
- Platform/OS: macOS (Darwin 25.5.0, arm64)
- Browser: Chrome 150.0.7871.115
Activity
bot14412 commentedon Aug 13, 2026
Adding a clarification, since the framing above centres on
.mjs: the regex is an extension allowlist rather than an ESM question. Every extension Node type-strips fails it./\.c?js$/.js"type".cjs.mjs.ts"type".mts.ctsNote the last row:
.ctsis CommonJS,module.exports =, no ESM involved at all — and it still loses its template. So the issue is orthogonal to whether ESM nodes are supported. There is no extension that gets both native type stripping and a correct.htmlderivation.On the two reproductions above — the
.mjsone uses a package with no"type"field, the.tsone a package with"type": "module". Only the entry point extension is load-bearing in either case; the"type"field plays no part in the failure.Happy to open a PR for the one-line change if that's useful. Thanks for v5 — the import() rework in #4355 is what made this worth chasing.