# nodesDir crashes Node-RED 3.0?

**URL:** <https://discourse.nodered.org/t/nodesdir-crashes-node-red-3-0/67227>\
**Category:** Developing Nodes\
**Created:** [1 September 2022 18:40 UTC](https://discourse.nodered.org/t/nodesdir-crashes-node-red-3-0/67227 "2022-09-01T18:40:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![lhp](https://avatars.discourse-cdn.com/v4/letter/l/91b2a8/32.png) [@lhp](https://discourse.nodered.org/u/lhp)\
**Post date:** [1 September 2022 18:40 UTC](https://discourse.nodered.org/t/nodesdir-crashes-node-red-3-0/67227/1 "2022-09-01T18:40:23Z")

</div>

Hello,

I’m developing custom nodes in a directory specified with the nodesDir property in the settings.js file. This set-up used to work up to Node-RED 2.2.2. However, I’ve just upgraded to Node-RED 3.0.2 and now the server crashes immediately on start-up, using a settings.js file that used to work before the upgrade.

Here is the start-up log:

```auto
Welcome to Node-RED
===================
1 Sep 20:18:04 - [info] Node-RED version: v3.0.2
1 Sep 20:18:04 - [info] Node.js version: v16.17.0
1 Sep 20:18:04 - [info] Linux 5.10.0-9-amd64 x64 LE
1 Sep 20:18:04 - [info] Loading palette nodes
1 Sep 20:18:04 - [debug] Module: varenne-nodes 1.0beta1 /home/node-red/varenne-nodes
1 Sep 20:18:04 - [error] Failed to start server:
1 Sep 20:18:04 - [error] TypeError: Cannot read properties of undefined (reading 'forEach')
    at Object.addModule (/usr/lib/node_modules/node-red/node_modules/@node-red/registry/lib/registry.js:195:27)
    at /usr/lib/node_modules/node-red/node_modules/@node-red/registry/lib/loader.js:153:34

```

However, if I just remove the following line from my settings.js file, then Node-RED 3.0.2 will start normally ... but of course without my custom nodes.

`nodesDir: '/home/node-red/varenne-nodes'`

Could it be a regression with Node-RED 3.0 ? Or something specific to my environment ?

Any help will be appreciated.

---

<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:** [1 September 2022 19:02 UTC](https://discourse.nodered.org/t/nodesdir-crashes-node-red-3-0/67227/2 "2022-09-01T19:02:07Z")

</div>

Are you sure it is exactly that line you remove? Could you show us that section of the file with that line present?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [1 September 2022 19:20 UTC](https://discourse.nodered.org/t/nodesdir-crashes-node-red-3-0/67227/3 "2022-09-01T19:20:49Z")

</div>

Hi @lhp

Some of the logic around nodesDir did change in 3.0 - but should have been backwards compatible.

Can you raise an issue so we can investigate?

---

<div class="post-metadata">

**Author:** ![lhp](https://avatars.discourse-cdn.com/v4/letter/l/91b2a8/32.png) [@lhp](https://discourse.nodered.org/u/lhp)\
**Post date:** [1 September 2022 19:48 UTC](https://discourse.nodered.org/t/nodesdir-crashes-node-red-3-0/67227/4 "2022-09-01T19:48:17Z")

</div>

Hello,

I've created a GitHub issue to describe my problem

> <https://github.com/node-red/node-red/issues/3861>
>
> \### Current Behavior
> 
> I’m developing custom nodes in a directory specified with …the \*\*nodesDir\*\* property in the settings.js configuration file. This set-up used to work up to Node-RED 2.2.2. However, I’ve just upgraded to Node-RED 3.0.2, and now the server crashes immediately on start-up, using a settings.js file that used to work before the upgrade.
> 
> \### Expected Behavior
> 
> When the \*\*nodesDir\*\* property is used in the settings.js to specify a custom nodes directory, the server should not crash. If a problem is encountered, then the nature of this problem shall be described in the log output.
> 
> \### Steps To Reproduce
> 
> If I use the following \[settings.js\](https://www.celtrio.com/varenne/node-red/ok-settings.js), Node-RED 3.0.2 starts normally. Please note that some values have been redacted in this file for confidentiality reasons. This first settings.js file works with Node-RED 2.2.2
> 
> However, if I use this second \[settings.js\](https://www.celtrio.com/varenne/node-red/ko-settings.js) file, then the Node-RED 3.0.2 server crashes on start-up with the following output:
> 
> \`\`\`
> Welcome to Node-RED
> ===================
> 1 Sep 20:18:04 - \[info\] Node-RED version: v3.0.2
> 1 Sep 20:18:04 - \[info\] Node.js version: v16.17.0
> 1 Sep 20:18:04 - \[info\] Linux 5.10.0-9-amd64 x64 LE
> 1 Sep 20:18:04 - \[info\] Loading palette nodes
> 1 Sep 20:18:04 - \[debug\] Module: varenne-nodes 1.0beta1 /home/node-red/varenne-nodes
> 1 Sep 20:18:04 - \[error\] Failed to start server:
> 1 Sep 20:18:04 - \[error\] TypeError: Cannot read properties of undefined (reading 'forEach')
> at Object.addModule (/usr/lib/node\_modules/node-red/node\_modules/@node-red/registry/lib/registry.js:195:27)
> at /usr/lib/node\_modules/node-red/node\_modules/@node-red/registry/lib/loader.js:153:34
> \`\`\`
> 
> The only difference between these two settings.js files is the following line, which is present when the server crashes.
> 
> \`nodesDir: '/home/node-red/varenne-nodes'\`
> 
> 
> \### Example flow
> 
> With \*\*nodesDir\*\* set, Node-RED 3.0.2 crashes on start-up, even with an empty flow.
> 
> 
> \### Environment
> 
> \- Node-RED version: 3.0.2
> \- Node.js version: v16.17.0
> \- npm version: 8.19.0
> \- Platform/OS: Linux 5.10.0-9-amd64 #1 SMP Debian 5.10.70-1 (2021-09-30) x86\_64 GNU/Linux
> \- Browser: Not browser related

---

<div class="post-metadata">

**Author:** ![lhp](https://avatars.discourse-cdn.com/v4/letter/l/91b2a8/32.png) [@lhp](https://discourse.nodered.org/u/lhp)\
**Post date:** [1 September 2022 19:52 UTC](https://discourse.nodered.org/t/nodesdir-crashes-node-red-3-0/67227/5 "2022-09-01T19:52:14Z")

</div>

To given your more context, here are the settings.js files that I use; minus some values which have been redacted for obvious reasons.

[https://www.celtrio.com/varenne/node-red/ok-settings.js](https://www.celtrio.com/varenne/node-red/ok-settings.js)  
[https://www.celtrio.com/varenne/node-red/ko-settings.js](https://www.celtrio.com/varenne/node-red/ko-settings.js)

The first settings.js works fine with Node-RED 3.0.2. The second file crashes the server on start-up. The only difference is the presence of the **nodesDir** property in the second file.

---

<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:** [1 September 2022 19:56 UTC](https://discourse.nodered.org/t/nodesdir-crashes-node-red-3-0/67227/6 "2022-09-01T19:56:31Z")

</div>

So the line you took out is actually  
`nodesDir: '/home/node-red/varenne-nodes',`  
which is not quite what you said. Had you not removed the trailing comma then I would have expected it to fail, though not in the way you said. Since you have also removed the comma then there does appear to be an issue.  
It would probably be worth correcting the issue on github, just to avoid confusion.

---

<div class="post-metadata">

**Author:** ![lhp](https://avatars.discourse-cdn.com/v4/letter/l/91b2a8/32.png) [@lhp](https://discourse.nodered.org/u/lhp)\
**Post date:** [2 September 2022 08:22 UTC](https://discourse.nodered.org/t/nodesdir-crashes-node-red-3-0/67227/7 "2022-09-02T08:22:58Z")

</div>

Hello @Colin,

Thank you for looking into my problem. Unfortunately, the problem is not a syntax error in settings.js.

If I move my custom nodes from **nodesDir** to the default **./node-red/nodes**... then Node-RED will start normally, with my custom nodes. This looks like a regression with Node-RED 3 on the nodesDir setting.

I've updated the GitHub issue with this new information.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [2 September 2022 08:46 UTC](https://discourse.nodered.org/t/nodesdir-crashes-node-red-3-0/67227/8 "2022-09-02T08:46:40Z")

</div>

@lhp can you respond to the questions on the issue please? I would like to get the the bottom of this. Thanks for the feedback.

---

<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:** [1 November 2022 08:47 UTC](https://discourse.nodered.org/t/nodesdir-crashes-node-red-3-0/67227/9 "2022-11-01T08:47:20Z")

</div>

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