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

**URL:** <https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467>\
**Category:** Developing Nodes\
**Tags:** docker\
**Created:** [21 September 2023 05:37 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467 "2023-09-21T05:37:03Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![nbuhl](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@nbuhl](https://discourse.nodered.org/u/nbuhl)\
**Post date:** [21 September 2023 05:37 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/1 "2023-09-21T05:37:03Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/2/c29263c821ed9ed1de70c3fc331330e879166752.png)

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:

```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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/a/4aee6ea3b15f8480b66ef9a18f8b721b00bea860.png)

Any ideas?  
Thank in advance!

nico

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 September 2023 08:29 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/2 "2023-09-21T08:29:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nbuhl](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@nbuhl](https://discourse.nodered.org/u/nbuhl)\
**Post date:** [21 September 2023 08:34 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/3 "2023-09-21T08:34:20Z")

</div>

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)](https://nodered.org/docs/creating-nodes/subflow-modules#add-your-subflow-json)

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.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 September 2023 08:46 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/4 "2023-09-21T08:46:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nbuhl](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@nbuhl](https://discourse.nodered.org/u/nbuhl)\
**Post date:** [21 September 2023 10:20 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/5 "2023-09-21T10:20:16Z")

</div>

Exactly!

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

```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`:

```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`:

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

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 September 2023 11:05 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/6 "2023-09-21T11:05:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nbuhl](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@nbuhl](https://discourse.nodered.org/u/nbuhl)\
**Post date:** [21 September 2023 11:16 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/7 "2023-09-21T11:16:03Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 September 2023 12:06 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/8 "2023-09-21T12:06:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nbuhl](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@nbuhl](https://discourse.nodered.org/u/nbuhl)\
**Post date:** [21 September 2023 12:17 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/9 "2023-09-21T12:17:18Z")

</div>

Like this? 🙂

[buhln/node-red-subflow-example (github.com)](https://github.com/buhln/node-red-subflow-example/)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 September 2023 12:56 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/10 "2023-09-21T12:56:14Z")

</div>

When I try to install I get

```auto
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.

---

<div class="post-metadata">

**Author:** ![nbuhl](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@nbuhl](https://discourse.nodered.org/u/nbuhl)\
**Post date:** [21 September 2023 13:01 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/11 "2023-09-21T13:01:10Z")

</div>

> [@Colin](#):
>
> `npm install buhin/node-red-subflow-example`

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 September 2023 13:07 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/12 "2023-09-21T13:07:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nbuhl](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@nbuhl](https://discourse.nodered.org/u/nbuhl)\
**Post date:** [21 September 2023 13:13 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/13 "2023-09-21T13:13:54Z")

</div>

Great! Thanks for your patient! 👍

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 September 2023 13:57 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/14 "2023-09-21T13:57:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nbuhl](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@nbuhl](https://discourse.nodered.org/u/nbuhl)\
**Post date:** [26 September 2023 07:44 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/15 "2023-09-26T07:44:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 September 2023 08:11 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/16 "2023-09-26T08:11:59Z")

</div>

If you change the subflow contents does it work?

---

<div class="post-metadata">

**Author:** ![nbuhl](https://avatars.discourse-cdn.com/v4/letter/n/ecccb3/32.png) [@nbuhl](https://discourse.nodered.org/u/nbuhl)\
**Post date:** [26 September 2023 08:27 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/17 "2023-09-26T08:27:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 November 2023 08:28 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-properties-of-undefined-in-subflow-module/81467/18 "2023-11-25T08:28:44Z")

</div>

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