Installing a module fails to install dependencies?

I'm having difficulties with NPM dependency installation. It's not happening the way I would hope it would... Specifically:

    bash-5.0$ ls /data/node_modules/@flexdash
    node-red-fd-corewidgets  node-red-flexdash
  • but the palette manager doesn't show node-red-flexdash installed:
  • the nodes of node-red-flexdash don't show up in the palette
  • when I instantiate a node from node-red-fd-corewidgets it needs a config node from the other repo, and the input field that should show a drop down with the config nodes or "Add a new config node..." doesn't work
  • if I go back to the palette manager and manually install node-red-flexdash then its nodes get recognized, become available in the palette, and everything works

Am I doing something wrong or is there a bug or is this "as designed"?

Node-RED log:

Welcome to Node-RED
===================

18 Mar 22:00:38 - [info] Node-RED version: v2.2.2
18 Mar 22:00:38 - [info] Node.js  version: v14.18.2
18 Mar 22:00:38 - [info] Linux 5.13.0-27-generic x64 LE
18 Mar 22:00:38 - [info] Loading palette nodes
18 Mar 22:00:39 - [info] Settings file  : /data/settings.js
18 Mar 22:00:39 - [info] Context store  : 'default' [module=memory]
18 Mar 22:00:39 - [info] User directory : /data
18 Mar 22:00:39 - [warn] Projects disabled : editorTheme.projects.enabled=false
18 Mar 22:00:39 - [info] Flows file     : /data/flows.json
18 Mar 22:00:39 - [warn]
18 Mar 22:00:39 - [info] Server now running at http://127.0.0.1:1880/
18 Mar 22:00:39 - [info] Starting flows
18 Mar 22:00:39 - [info] Started flows
18 Mar 22:01:08 - [info] Installing module: @flexdash/node-red-fd-corewidgets, version: 0.1.4
18 Mar 22:01:19 - [info] Installed module: @flexdash/node-red-fd-corewidgets
18 Mar 22:01:19 - [info] Added node types:
18 Mar 22:01:19 - [info]  - @flexdash/node-red-fd-corewidgets:date-time
18 Mar 22:01:19 - [info]  - @flexdash/node-red-fd-corewidgets:gauge
...
18 Mar 22:01:19 - [info]  - @flexdash/node-red-fd-corewidgets:value-sequence
18 Mar 22:01:19 - [info]  - @flexdash/node-red-fd-corewidgets:wind-plot

When you install a module, the runtime only knows you want to use that one module. So once the install completes it loads that module.

The runtime doesn't rescan the entire npm module tree to see what other modules got installed that might also be Node-RED modules.

A restart of Node-RED would trigger a full rescan and find the extra modules.

There is a long standing item in the backlog to support this type of scenario - but there hasnt been much demand so it hasn't got off the backlog.

1 Like

I see, thanks for the quick reply! Is there a call I can make for now that would scan the other package for nodes?

No, the only option is to restart node-red, or ask the manage pallet option to install the dependencies again

Looks like the backlog item is Allow node modules to have node modules as dependencies · Issue #569 · node-red/node-red · GitHub
Am I right that what's really missing is a call

registry.addModule('node-red-flexdash')

?

If you're looking for API calls you could make, then no. That is a deeply internal API and shouldn't be called directly.

I was wondering about starting a PR, but it looks like the enthusiasm for getting this fixed is near zero, so be it...

It would be great to get it fixed to support this behaviour.

My lack of enthusiasm was for someone to hack something into their node to try and bypass what we have. Sadly that happens quite often - people choose to do their own thing rather than contribute back.

If this is something you're interested in contributing to, that would be awesome. I'd be happy to give some more detailed pointers - I'm just not in a position to do that right now.

1 Like

Hmm, trying to understand what's needed. So we land in installModule:

and then it proceeds to addModule, which has the following intriguing loop:

But that already looks at dependencies!? Specifically moduleFiles[moduleToLoad].dependencies and adds those to the stack!? The dependencies seem to be established in

Does that mean all I'm missing is some json in my package.json? E.g. in addition to

  "dependencies": {
    "@flexdash/node-red-flexdash": ">=0.3.7"
  },

I should also have

  "node-red": {
    "dependencies": [
      "@flexdash/node-red-flexdash"
    ]
  }

Or am I completely mis-understanding what the code is trying to do?

1 Like

@tve, it would be worth a shot adding that to your package. Please let us know if that does the trick.

1 Like

Nope, doesn't work. In fact, even if I install the dependency manually that "dependencies" added to package.json will actively prevent the nodes from the dependency from being added to the palette.

As a follow-up, the current state I'm facing is:

  • Flexdash needs 3 packages, prob 4:
    • node-red-flexdash: core of flexdash, primarily configuration nodes
    • node-red-flexdash-plugin: flexdash plugin due to bug described in How do Node-RED plugins work? (can't reliably have a plugin and a node in the same pkg)
    • node-red-fd-corewidgets: core set of widget nodes, really separable from the core of flexdash as someone could install a different set of widgets
    • node-red-flexdash-sidebar: sidebar for FlexDash, which perhaps should/could be integrated into the node-red-flexdash package, or perhaps not
  • While the instructions can tell someone to "npm install node-red-fd-corewidgets" and get everything else pulled in as dependencies, due to the bug described here this is not possible through the palette manager: the dependencies get pulled in at the npm level but not their nodes and thus users end up with missing nodes. Instead users have to select all 3 or 4 packages for install manually in the palette manager.
  • In order to allow the manual install of all the dependencies in the palette manager, I have to publish all these packages in the flow library, which due to the fact that it can't be automated is both painful and error prone (see Script to trigger flow library update after npm publish?)

If I'm missing a solution to all this I'd be grateful to hear!

Edit: Ticket about the failure to install nodes in dependencies: When installing packages using palette manager the nodes of dependencies are not discovered · Issue #3529 · node-red/node-red · GitHub