Error in 3.0 upgrade notes. BIG problem with latest Node.JS (v16.6)

In the upgrade notes for v3.0 it says: " Node.js 14.x or later required" ;
foolishly assuming that meant that the latest version of Node.js had been tested, I blithely installed the latest version, 16.16.0 LTS (Recommended For Most Users).

When I restarted node-red, I got the following error:

18 Jul 18:11:10 - [info] Node-RED version: v3.0.0
18 Jul 18:11:10 - [info] Node.js  version: v16.16.0
18 Jul 18:11:10 - [info] Windows_NT 10.0.18363 x64 LE
...
18 Jul 18:11:20 - [red] Uncaught Exception:
18 Jul 18:11:20 - [error] TypeError: cb.apply is not a function
    at C:\Users\williams_b\.node-red\node_modules\npm\node_modules\graceful-fs\polyfills.js:287:18
    at FSReqCallback.oncomplete (node:fs:199:5)

Googling the error, I found it was mostly related to Node.js upgrades, so I uninstalled it (thankfully easy on windows) and downloaded the 14.0 (the lowest number required).

I now start as

19 Jul 11:05:29 - [info] Node-RED version: v3.0.0
19 Jul 11:05:29 - [info] Node.js  version: v14.0.0
19 Jul 11:05:29 - [info] Windows_NT 10.0.18363 x64 LE

and everything is now running.... Phew!

So, recommendation to @knolleary , unless this is an idiosyncratic problem for me, it might be best to edit your upgrade notes with a warning not to upgrade Node.js greater than the latest version you know that it runs on.

Lastly, what I find astonishing is that if you google

"node_modules\npm\node_modules\graceful-fs\polyfills.js:287:18"

you get about 1,350 results, many of which refer to versions of Node.js lower than 14, so I do not understand why the problem has not recurred.

Brian

Assuming that you were running with a lower version before the nodejs upgrade to 16, did you remember to go into your .node-red folder and run npm rebuild?

Many thousands (I guess) are running with v16 now so it is not a general problem.

Also make sure you are using the latest versions of all nodes you have installed (using Manage Palette in the dropdown menu).

What is importing that module?

At a command line in directory C:\Users\williams_b\.node-red what does npm list graceful-fs reveal?

Hi @Colin thanks for that useful snippet!

Answer: I would have done if it was in the documentation that I was pointed to. It might be more obvious to developers than home users.

That's not meant to be a criticism, just that some of we whitebeards stopped programming for a living when Fortran77 was still in use! Hence the appeal of node-red.

So, if npm rebuild is needed, and Node-red is the low code environment it is meant to be, I think it really ought to be included in the upgrade information here that is referenced in the release announcement.

Having just googled node red how to upgrade "node.js" , I found this which is clearly the very thing I needed to read!

I strongly recommend that a link to it is included in the "upgrading" section of your "installing node red" that is referenced in the release announcement. It might have saved me having to downgrade.

Do you think there would be any value in doing the npm rebuild now?

Thanks again!

1 Like

Hi @Steve-Mcl !
Another useful snippet!

It seems I now need to downgrade npm!

C:\Users\williams_b>npm list graceful-fs
npm does not support Node.js v14.0.0
You should probably upgrade to a newer version of node as we
can't make any promises that npm will work with this version.
You can find the latest version at https://nodejs.org/
williams_b@ C:\Users\williams_b
`-- graceful-fs@4.2.10

No, you need to upgrade NODE back to 16 and fix the below

This is the problem ↑ Its too old.

Once you are back on NODE 16, run that command again. It will tell you which node is importing this old version of graceful-fs - then you can either request the contrib node be updated OR try fixing it yourself (we can help with that)

Will do - I will report back. Many thanks!

by the way .. you didnt run npm list graceful-fs from the .node-red folder

Oh, I might be wrong on that

EDIT - I think it is because you ran the command from the wrong directory

@UnborN @Steve-Mcl
Oops, sorry about that!

Interesting, depending on the directory, I get different results.

Here is where the main installation is:

C:\Users\williams_b\AppData\Roaming\npm>npm list graceful-fs
C:\Users\williams_b\AppData\Roaming\npm
+-- node-red@3.0.0 extraneous
| +-- fs-extra@10.1.0 extraneous
| | `-- graceful-fs@4.2.10 deduped
| +-- graceful-fs@4.2.10 extraneous
| `-- jsonfile@6.1.0 extraneous
|   `-- graceful-fs@4.2.10 deduped
`-- npm@8.14.0 extraneous
  +-- graceful-fs@4.2.10 extraneous
  +-- node-gyp@9.0.0 extraneous
  | `-- graceful-fs@4.2.10 deduped
  `-- readdir-scoped-modules@1.1.0 extraneous
    `-- graceful-fs@4.2.10 deduped

and here is where my local modules are stored, where the problem lies, I guess.

node-red-project@0.0.1 C:\Users\williams_b\.node-red
+-- node-red-contrib-function-npm@0.3.0
| `-- npm@5.10.0
|   +-- bin-links@1.1.0
|   | `-- graceful-fs@4.1.11 deduped
|   +-- cacache@10.0.4
|   | `-- graceful-fs@4.1.11 deduped
|   +-- cmd-shim@2.0.2
|   | `-- graceful-fs@4.1.11 deduped
|   +-- fs-vacuum@1.2.10
|   | `-- graceful-fs@4.1.11 deduped
|   +-- fs-write-stream-atomic@1.0.10
|   | `-- graceful-fs@4.1.11 deduped
|   +-- gentle-fs@2.0.1
|   | `-- graceful-fs@4.1.11 deduped
|   +-- graceful-fs@4.1.11
|   +-- libcipm@1.6.2
|   | `-- graceful-fs@4.1.11 deduped
|   +-- node-gyp@3.6.2
|   | +-- fstream@1.0.11
|   | | `-- graceful-fs@4.1.11 deduped
|   | `-- graceful-fs@4.1.11 deduped
|   +-- npm-lifecycle@2.0.1
|   | `-- graceful-fs@4.1.11 deduped
|   +-- npm-registry-client@8.5.1
|   | `-- graceful-fs@4.1.11 deduped
|   +-- read-cmd-shim@1.0.1
|   | `-- graceful-fs@4.1.11 deduped
|   +-- read-installed@4.0.3
|   | `-- graceful-fs@4.1.11 deduped
|   +-- read-package-json@2.0.13
|   | `-- graceful-fs@4.1.11 deduped
|   +-- readdir-scoped-modules@1.0.2
|   | `-- graceful-fs@4.1.11 deduped
|   +-- sha@2.0.1
|   | `-- graceful-fs@4.1.11 deduped
|   +-- update-notifier@2.5.0
|   | `-- configstore@3.1.2
|   |   `-- graceful-fs@4.1.11 deduped
|   `-- write-file-atomic@2.3.0
|     `-- graceful-fs@4.1.11 deduped
`-- node-red-contrib-nbrowser@1.1.4
  `-- nightmare@2.10.0
    `-- electron@1.8.8
      `-- electron-download@3.3.0
        +-- fs-extra@0.30.0
        | +-- graceful-fs@4.2.3
        | +-- jsonfile@2.4.0
        | | `-- graceful-fs@4.2.3 deduped
        | `-- klaw@1.3.1
        |   `-- graceful-fs@4.2.3 deduped
        `-- nugget@2.0.1
          `-- pretty-bytes@1.0.4
            `-- meow@3.7.0
              `-- read-pkg-up@1.0.1
                `-- read-pkg@1.1.0
                  +-- load-json-file@1.1.0
                  | `-- graceful-fs@4.2.3 deduped
                  `-- path-type@1.1.0
                    `-- graceful-fs@4.2.3 deduped

Do you think a npm rebuild would fix this?

Also, according to the documentation, I could run it in either location, but would it not be better to run it in both?

2 things.

  1. node-red-contrib-function-npm@0.3.0 is old ( 0.4.3 is current version in NPM)
  2. Do you even need node-red-contrib-function-npm? (the function node can now import modules directly)

I've gained more wisdom here today than ever before! :slightly_smiling_face:

I was just looking at that contrib on Github and saw a warning from (I guess) a node-red developer called Sam Machin warning that it would break in Node-red 2.0 (I was running 1.3.5) . Looks like the developer stopped before then because it was the last issue left unanswered.

Presumably this is because of the new feature I have yet to take advantage of!

Could you point me at where it is documented? Sorry to be so helpless!

Also, should I run npm rebuild in both those directories I mentioned earlier?

regarding importing and using modules in the Node-red Function node

Here :
https://nodered.org/docs/user-guide/writing-functions#using-the-functionexternalmodules-option

That is talking about upgrading node-red, npm rebuild is not necessary after upgrading node-red, but it may be required after upgrading (or downgrading) nodejs. I am not sure whether there is a section in the docs on upgrading nodejs, but if not then I agree that it would be a useful addition.

As stated earlier, npm rebuild should be run from the .node-red directory. It will not fix problems caused by modules that do not work with later versions of nodejs, it is purely to rebuild any modules that include native code, as they need to be rebuilt to be compatible with the new nodejs version.

If you follow the rest of that message down, you'll find the very reference here , which I think needs to be linked to from the upgrade document.

That is talking about upgrading node-red, npm rebuild is not necessary after upgrading node-red, but it may be required after upgrading (or downgrading) nodejs

Quite so. But a node-red ugrade does sometimes require a Node.js upgrade as in this case, so a link to these notes are critical.

But by the by, I still need to know where to run npm rebuild (since I have upgraded Node.js) and the document is ambiguous.

It says:

This can be done using the command npm rebuild - but it must be run in the right directory.

The "right directory" is singular

There are two places it should be run:

  1. In your Node-RED user directory, ~/.node-red - this is where any additional nodes you have installed are.
  2. In the directory you installed Node-RED

This is the ambiguous bit. "two places" is plural. It could mean both places or either-or.

Regardless of the true answer, I think that document needs rephrasing.

Can you help me with the true answer?

Thanks!

As stated earlier, npm rebuild should be run from the .node-red directory.

Ah, I didn't see this before I replied to your earlier.

So you probably are unaware of the ambiguous bit in the referenced document.

I wonder why it gives two locations?

@knolleary could you comment on this please? The docs for upgrading nodejs (Supported Node versions : Node-RED) says that npm rebuild should be also be run in the node-red install directory. Is that still the case? I have never done that as far as I can remember.

regarding importing and using modules in the Node-red Function node

Many thanks!