Unable to start node-red after attempted upgrade - Cannot find module 'node:dns'

Starting a new project so figured it would be good to start with the latest release of node-red. Per the nodered.org site, I ran this from the Windows command prompt thinking it would do the trick:
npm install -g --unsafe-perm node-red
After allowing this to run, attempted to restart node-red and, unfortunately, that didn't go as expected. Nothing I have found thus far have allowed me to correct the problem. Any guidance is appreciated.

C:\Users\Ray>node-red
node:internal/modules/cjs/loader:927
  throw err;
  ^

Error: Cannot find module 'node:dns'
Require stack:
- C:\Users\Ray\AppData\Roaming\npm\node_modules\node-red\lib\red.js
- C:\Users\Ray\AppData\Roaming\npm\node_modules\node-red\red.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.<anonymous> (C:\Users\Ray\AppData\Roaming\npm\node_modules\node-red\lib\red.js:30:17)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Module.require (node:internal/modules/cjs/loader:996:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\Ray\\AppData\\Roaming\\npm\\node_modules\\node-red\\lib\\red.js',
    'C:\\Users\\Ray\\AppData\\Roaming\\npm\\node_modules\\node-red\\red.js'
  ]
}

What version of Node-RED and node.js do you have installed? I think that the node.js node:dns module is only available from node.js v18. It was called dns before.

The blog entry for rhe release of v3.1 led to the get started page where with the command shown above to upgrade. No version is referenced so assume it would pull the latest at 3.1.x.
https://nodered.org/docs/getting-started/local

It is mentioned on that page, as you referenced in your reply, a compatable version of jode.js. I will check/upgrade and report back.

Thank you!

Node.js update from 15.14.0 to 21.6.0 and an npm rebuild did the trick!
Thank you very much!

@knolleary , @Steve-Mcl - is this a bug in the latest release of Node-RED? As Node-RED v3 is meant to be baselined against Node.js v14, I think it should be using the dns module and not node:dns?

The use of node:dns is guarded behind a check of the node.js version... need to figure out how/why that isn't doing what is expected.

1 Like

I thought you could still use just dns? Though, to be honest, I've not checked that module. I've been more focused on the fs module recently.

Looking at the node docs, node:dns first shows up in v16.

Therefore the guard is not adequate to cover odd versions (pretty sure the docs do state dont use odd numbered versions of node :stuck_out_tongue: )

In short, the guard should probably check for >= 16 (not just > 14)

In this instance,we want to call a function of the DNS module that was introduced after Node 14 - which is why it makes the check. That said, you are quite right that it doesn't need to use the node: prefix either way.

I have another bug to fix before anyone sees it in the wild and will be doing 3.1.5 release in the next 24 hours. I'll update this require statement as well.

2 Likes

Dare I ask about v4? :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.