"TypeError: Cannot read properties of undefined ... in subflow module

Hi!
This is my first post in this forum but I am using Node-RED for some long time and I have to say it is a great tool for fast programming interfaces in an industrial context, too. So, thanks to all professional and voluntary developers who made this tool possible.

But back to my issue...

I created a subflow and packed it as a module accordingly to the howto in the docs. This package is hosted on a private Gitlab instance and also hosted as an npm package in a private registry. This workflow works fine and at the and I have an installed node-red package in an running docker container I deployed from this registry to.

I show here now a simple example to demonstrate my issue...

The subflow node is available in the palette:

image

If I add the node to the flow and deploy it, I will get an TypeError: Cannot read properties of undefined (reading '_originalWires').

With a more complex subflow the property which is not readable changes but it is all the time a TypeError: Cannot read,...

Here the subflow JSON:

{
    "id": "testsubflow",
    "type": "subflow",
    "name": "Testsubflow",
    "info": "",
    "category": "",
    "in": [
        {
            "x": 380,
            "y": 160,
            "wires": []
        }
    ],
    "out": [
        {
            "x": 660,
            "y": 240,
            "wires": [
                {
                    "id": "b162a17b6d3cda34",
                    "port": 0
                },
                {
                    "id": "f6c5c0739395d41c",
                    "port": 0
                }
            ]
        }
    ],
    "env": [],
    "meta": {},
    "color": "#DDAA99",
    "flow":
    [
        {
            "id": "b162a17b6d3cda34",
            "type": "inject",
            "z": "f6c5c0739395d41c",
            "name": "",
            "props": [
                {
                    "p": "payload"
                }
            ],
            "repeat": "1",
            "crontab": "",
            "once": false,
            "onceDelay": 0.1,
            "topic": "",
            "payload": "",
            "payloadType": "date",
            "x": 450,
            "y": 240,
            "wires": [
                []
            ]
        }
    ]
}

It is quiet simple, it contains just an inject node which injects the actual timestamp to an output.

image

Any ideas?
Thank in advance!

nico

The flow is not importable. Please construct a simple flow that shows the problem then use the Export feature to export to clipboard and paste here. The export will automatically include the subflow. Then we can import it and try to replicate the problem.

Hi!
The json definition is already changed accordingly to the documentation for packing a subflow in a module.

Packaging a Subflow as a module : Node-RED (nodered.org)

So this flow will not be possible to reimport directly to NodeRED. You have to embed this in a nodered package and install it for using the embedded subflow.

Do you mean that it works fine when used as a subflow, but fails when packaged as a module? If so then point us to the repository where you have packaged it, so we can try it.

Exactly!

The already posted code is located in the file subflow.json:

{
    "id": "testsubflow",
    "type": "subflow",
    "name": "Testsubflow",
    "info": "",
    "category": "",
    "in": [
        {
            "x": 380,
            "y": 160,
            "wires": []
        }
    ],
    "out": [
        {
            "x": 660,
            "y": 240,
            "wires": [
                {
                    "id": "b162a17b6d3cda34",
                    "port": 0
                },
                {
                    "id": "f6c5c0739395d41c",
                    "port": 0
                }
            ]
        }
    ],
    "env": [],
    "meta": {},
    "color": "#DDAA99",
    "flow":
    [
        {
            "id": "b162a17b6d3cda34",
            "type": "inject",
            "z": "f6c5c0739395d41c",
            "name": "",
            "props": [
                {
                    "p": "payload"
                }
            ],
            "repeat": "1",
            "crontab": "",
            "once": false,
            "onceDelay": 0.1,
            "topic": "",
            "payload": "",
            "payloadType": "date",
            "x": 450,
            "y": 240,
            "wires": [
                []
            ]
        }
    ]
}

Here is the js wrapper file subflow.js:

const fs = require("fs");
const path = require("path");

module.exports = function(RED) {
    const subflowFile = path.join(__dirname,"subflow.json");
    const subflowContents = fs.readFileSync(subflowFile);
    const subflowJSON = JSON.parse(subflowContents);
    RED.nodes.registerSubflow(subflowJSON);
}

This is the package.json:

{
  "name": "@scope/node-red-example-subflow",
  "version": "0.0.6",
  "description": "subflow descripton",
  "node-red": {
    "nodes": {
        "example_subflow": "subflow.js"
    }
  },  
  "author": "",
  "license": "ISC"
}

Why don't you just point us to the repository so we can install it?

Sorry, it is a privat repo and not possible to access from outside of our network.

I hope you can find the error in the subflow.json. I guess it is in that file because the installation of the module in node red works fine.

Edit: I will prepare a tar archive for installing the package.

Edit2: Done. Can you recommend a one-click file hoster for this purpose?

Put the module on a public GitHub repo. Then we can install straight from there

Like this? :slightly_smiling_face:

buhln/node-red-subflow-example (github.com)

When I try to install I get

npm install buhin/node-red-subflow-example
npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/buhin/node-red-subflow-example.git
npm ERR! ERROR: Repository not found.
npm ERR! fatal: Could not read from remote repository.

It isn't a git repository.

Try npm install buhln/node-red-subflow-example. Small L not an i in the username.

Sorry, I misread it. Installed ok now and seeing the error. Will have a look.

Great! Thanks for your patient! :+1:

I can't see anything wrong with your code. Hopefully someone else will be able to see something.

Should I open an issue in the node-red github repo?

If you change the subflow contents does it work?

No, I tried it with a more complex subflow. I get all the time a "TypError: Cannot read properties of undefined..." The property which is not readable changes but all the time a TypError.

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