Node-RED update 19.0.0 doesn't start

Today I decided to update a hassio integration. All works fine like always, aparto of Node-RED 19. The integration won’t start and I’am not able to figure out why. I also try to start it on safe mode but without success.
This is the log:

-----------------------------------------------------------
 Add-on: Node-RED
 Flow-based programming for the Internet of Things
-----------------------------------------------------------
 Add-on version: 19.0.0
 You are running the latest version of this add-on.
 System: Home Assistant OS 14.1  (amd64 / qemux86-64)
 Home Assistant Core: 2025.1.0
 Home Assistant Supervisor: 2024.12.3
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
s6-rc: info: service base-addon-banner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service base-addon-log-level: starting
s6-rc: info: service fix-attrs successfully started
Log level is set to INFO
s6-rc: info: service base-addon-log-level successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service init-nginx: starting
s6-rc: info: service init-customizations: starting
s6-rc: info: service init-customizations successfully started
s6-rc: info: service init-nodered: starting
s6-rc: info: service init-nginx successfully started
up to date, audited 1055 packages in 10s
116 vulnerabilities (10 low, 26 moderate, 65 high, 15 critical)
To address issues that do not require attention, run:
  npm audit fix
To address all issues possible (including breaking changes), run:
  npm audit fix --force
Some issues need review, and may require choosing
a different dependency.
Run `npm audit` for details.
s6-rc: info: service init-nodered successfully started
s6-rc: info: service nodered: starting
s6-rc: info: service nodered successfully started
s6-rc: info: service nginx: starting
s6-rc: info: service nginx successfully started
s6-rc: info: service legacy-services: starting
[17:18:50] INFO: Setting safe mode startup
[17:18:50] INFO: Starting Node-RED...
s6-rc: info: service legacy-services successfully started
> start
> node $NODE_OPTIONS node_modules/node-red/red.js --safe --settings /etc/node-red/config.js
5 Jan 17:18:50 - [info] 
Welcome to Node-RED
===================
5 Jan 17:18:50 - [info] Node-RED version: v4.0.8
5 Jan 17:18:50 - [info] Node.js  version: v22.11.0
5 Jan 17:18:50 - [info] Linux 6.6.66-haos x64 LE
5 Jan 17:18:51 - [info] Loading palette nodes
5 Jan 17:18:51 - [info] Node-RED Contrib Theme Collection version: v4.0.11
Sun, 05 Jan 2025 16:18:52 GMT node-telegram-bot-api deprecated Automatic enabling of cancellation of promises is deprecated.
In the future, you will have to enable it yourself.
See https://github.com/yagop/node-telegram-bot-api/issues/319. at node:internal/modules/cjs/loader:1546:14
5 Jan 17:18:53 - [info] Dashboard version 3.6.5 started at /endpoint/ui
(node:369) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
5 Jan 17:18:53 - [red] Uncaught Exception:
5 Jan 17:18:53 - [error] ReferenceError: require is not defined
    at file:///config/node_modules/safefs/es6/lib/safefs.js:2:16
    at ModuleJobSync.runSync (node:internal/modules/esm/module_job:366:35)
    at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:325:47)
    at loadESMFromCJS (node:internal/modules/cjs/loader:1381:24)
    at Module._compile (node:internal/modules/cjs/loader:1503:5)
    at Object..js (node:internal/modules/cjs/loader:1689:10)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:141:16)
    at Object.<anonymous> (/config/node_modules/safefs/es6guardian.js:11:20)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Object..js (node:internal/modules/cjs/loader:1689:10)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:141:16)
    at Object.<anonymous> (/config/node_modules/scandirectory/out/lib/scandirectory.js:9:12)
[17:18:53] INFO: Service Node-RED exited with code 1 (by signal 0)
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service nginx: stopping
[17:18:53] INFO: Service NGINX exited with code 256 (by signal 15)

Can someone help me to figure out where is the problem?

First question would be "What is the processor you are using? Is it arm?
New version has removed the arm processor 32 bit support.

Edited for clarification

The new Node-RED version is running fine on my HA-Yellow. So why is it broken for others than? @Biscuit

Are those installs (like VMs or containers running in 32 bit mode)?

No it didn’t. Node.js removed support for 32 bit OS’s. ARMv7 is 32 bit only. Pi 3 and up have ARMv8 processors (64 bi) and is still fully supported.

Is a virtual machine on Proxmox server.

The latest Node-RED HA add-on update to 19.0.0 is a significant update.

As part of this update, the underlying NodeJS is updated, from v18.20.4 to v22.x
NOTE → version 22

I quote:

this release upgraded Alpine Linux to 3.21 and NodeJS to 22.x, making this a huge upgrade.

Going back to the Node-RED website, that site currently recommends NodeJS 20.x

At this time, I believe that Node-RED does not (officially) support Node.js v22. I quote from a recent (Nov 24) forum post:

Node-RED itself (the core) will of course support Node 22 - and we will recommend that as and when we think it doesn’t cause too many panic warnings like above :slight_smile:

Updating Node.js in Node-RED installations potentially requires quite a bit of work.

Upgrading Node.js

If you change the version of Node.js you are using, you may need to rebuild Node-RED’s dependencies as well as any nodes you have installed. This is because some of them contain binary components that must be rebuilt to be compatible with the new Node.js version.

Note also, from Node-RED website:

With such a large community of 3rd party nodes available to install, we cannot provide any guarantees on what they support.

Your error log:

DeprecationWarning: The punycode module is deprecated.

The punycode module was deprecated in Node.js version 21. Any nodes that still use this module will have to be changed to use something else.

5 Jan 17:18:53 - [red] Uncaught Exception:
5 Jan 17:18:53 - [error] ReferenceError: require is not defined
at file:///config/node_modules/safefs/es6/lib/safefs.js:2:16
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:366:35)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:325:47)

From the NodeJS v22 release announcement:

Support require()ing synchronous ESM graphs

This release adds require() support for synchronous ESM graphs under the flag --experimental-require-module.

If --experimental-require-module is enabled, and the ECMAScript module being loaded by require() meets the following requirements:

  • Explicitly marked as an ES module with a “type”: “module” field in the closest package.json or a .mjs extension.
  • Fully synchronous (contains no top-level await).

require() will load the requested module as an ES Module, and return the module name space object. In this case it is similar to dynamic import() but is run synchronously and returns the name space object directly. We intend to eventually enable require(esm) by default in the future, without the flag.

I don’t understand a word of this, but I suspect that the way esm modules are loaded using a require() has changed, and any nodes using this feature will have to be changed

My Conclusions:

  • Node-RED add-on 19+ has leapfrogged v20 to use NodeJS version 22
  • Node-RED recommends NodeJS 20, and is possibly not yet compatible with NodeJS 22.
  • Contrib nodes are potentially incompatible with NodeJS version 22
  • Changing NodeJS version may require a rebuild of the binaries, and this includes (some) installed contrib nodes
  • Node-RED add-on is a cut-down distribution and (AFAIK) does not include the code required to rebuild the binaries

This update may break a number of your additional contrib nodes

As far as I understand this, there is unlikely to be a short-term fix until any impacted contrib nodes are updated to support NodeJS v22.
Hence, either attempt to locate and fix any impacted contrib nodes yourself, attempt to revert the add-on to NodeJS v20, or revert to the previous add-on.

Personally I am going to stick with my current Node-RED add-on until such time as I know for certain that Node-RED and my installed contrib notes can actually run on NodeJS v22.

2 Likes

Wow thanks a lot @Biscuit , for this wonderful reply.
I restore from backup the previous version on Node-RED i as your suggestion I will wait until the future updates return to work.

The new Node-RED add-on version 19 uses a base NodeJS version (which is used to run Node-RED) that is more recent than the version supported by Node-RED itself.

The latest version of NodeJS (v22) uses new features and has breaking changes that may (and I repeat may) impact some of the contrib nodes that others have installed.

If (if) you have only the basic Node-RED nodes, then it is likely (but not yet guaranteed) that these will run successfully under NodeJS v22.

If, however, you have certain (older) contrib nodes that, for example, use punycode module, then since this module has been deprecated in NodeJS version 21, updating the underlying NodeJS version from 18 to 22 will mean that, any nodes where the code still uses punycode module, will have problems (since this module no longer exists in NodeJS after version 21)

The OP has, I suspect, many contrib nodes, and probably more than one that will not work correctly under NodeJS v22. I suspect that the primary issue is the change to the way ems modules are loaded by require() methods since NodeJS v22 makes significant changes in this area.

I use the addon, I’m updated without any problem and also have a good amount of additional nodes installed. I noticed in node modules folder .package-lock.json shows the dependencies of installed nodes.

You could search the document for punycode but I think it still could be nested in a different dependency.

Ok thanks, maybe I can do some test and research ragarding punycode with always a secure and working backup in local.

I’m having the same issue, no idea how to address. I read the release notes, but I don’t understand most of it, so I just backed up my whole HA instance, and upgraded Node Red. Then I did something colossally stupid, and updated HA to 2025, which introduces all the changes to HA Backups. Despite the (default) setting of retaining 3 backups, it only retained one…the one it carries out after the 2025 update when you are setting up backups. Luckily, I had them also being uploaded to Google Drive…but HA will allow them to be uploaded…then they disappear from the UI.

So, I cannot revert back to my old Node Red, which has all of my automations. I feel so dumb.

Me too, same issue here…

Instead of using the upload option from the backup page, copy it directly to the backup folder. You can use the samba addon to get ftp access to the file system. Then it should appear in backups.

FWIW I noticed that I have a depreciation warning for punycode. In .package-lock.json I see it is required for several nodes I have. I am also running the latest version of the addon(node.js 22) and it is just a warning.

There maybe something else going on like another node in the palette maybe needs updating.

I get the principles of evergreen patching but this feels like the HA stack has stepped beyond a supportable baseline, given node red recommends v20:

https://nodered.org/docs/faq/node-versions

You are true, tomorrow I retry to do the update, but I think nothing was patched. I don’t know what to do at this point, I use NodeRed a lot for automation. How can I figure out witch addon use a punnycode to try to delete it or replace it before update?

That page has not been update for over a year.

Updated: 2024-01-03

Node.js 20 is no longer active and is in maintenance mode. Node.js 22 is the active version. Node.js 23 is the most current version.

Node-RED officially supports only up to Node version 20, but the core nodes should all work with version 22. Problems are therefore going to lie with other contrib-nodes that are not yet compatible with v22, or have become incompatible with v22.

Ignoring the warning message over punnycode for a moment, the real ‘error’ seems to be from something attempting to ‘require’ a module but in an ESM loading approach.

In my very limited understanding, ‘require’ does not work in ES modules, and this error has been seen recently. The v22.x versions are exposing workarounds (“monkey patching”) that are now no longer effective following the v22 module loading changes.

The following post relates to the error ReferenceError: require is not defined

https://github.com/nodejs/node/issues/56140#issuecomment-2520787790

The suggestion is a package.json file, with the field "type": "module"

This is a known direct cause of the issue.

It may be worth going to your add-on configuration and the node modules folder, which I get to via Samba from my PC at:

addon_configs\a0d7b954_nodered\node_modules

If you have safefs as a module (or just search generally) look at the package.json file and check that it does not have type: module set.

I would like to suggest what safefs.js is, and why it is there, but have drawn a blank at this point.

1 Like

Wow thanks for the tips. I search the error line in

file:///config/node_modules/safefs/es6/lib/safefs.js:2:16

and at line 2 there is this:

const fsUtil = require(‘graceful-fs’)

I don’t see that as necessarily being the root cause of your error, however it confirms that you have module safefs, and this module is attempting to use ‘require’ to get another module on which it depends.

Quite what the link is between this and Node v22 is beyond me, but as a starting point perhaps you can work out what node installed or uses safefs and see if you can remove it…

I did an ai search and asked to dig through npm for nodes that require safefs.js. It found none. I then asked to look at the dependencies that require safefs, it returned these 4 nodes

  • node-red-contrib-fs-ops (link to node-red-contrib-fs-ops) allows performing basic file system operations like moving, copying, deleting, checking existence and accessibility, and getting file/directory size.
  • node-red-contrib-filesystem (link to node-red-contrib-filesystem) offers functionalities to work with the filesystem including copying, moving, linking, deleting files and folders, creating and listing folders, and getting file/folder information.
  • node-red-contrib-file-manager (link to node-red-contrib-file-manager) provides nodes to handle file system operations like saving files, moving files, and testing file/folder visibility, readability, or writability.
  • node-red-contrib-fs (link to node-red-contrib-fs) offers nodes for listing files and folders and copying files.

If you have one of these installed it maybe the cause.