# TypeError: Cannot read property 'forEach' of undefined

**URL:** <https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953>\
**Category:** General\
**Created:** [2 July 2021 18:34 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953 "2021-07-02T18:34:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![AngelMx3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/angelmx3/32/44025_2.png) [@AngelMx3](https://discourse.nodered.org/u/AngelMx3)\
**Post date:** [2 July 2021 18:34 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/1 "2021-07-02T18:34:14Z")

</div>

![Sin título](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/2/6242d86b71ec97bb3020113a207df9b48af02fba.png) Can someone help me, I get this and it won't let me start the server.

---

<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:** [2 July 2021 19:40 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/2 "2021-07-02T19:40:41Z")

</div>

What did you do that may have triggered that? Did you install a node or edit one of the files, for example?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [2 July 2021 23:43 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/3 "2021-07-02T23:43:51Z")

</div>

Did you edit settings.js? If so, check to see if you missed a comma or a bracket.  
If you can't find an error and haven't added anything that could comprimize your security, you could edit the file and copy it and paste it to a reply.

In order to make code more readable and importable it is important to surround your code with three backticks  
`````  
`like this`  
`````

You can edit and correct your post by clicking the pencil icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<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:** [2 July 2021 23:56 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/4 "2021-07-02T23:56:49Z")

</div>

@zenofmud this is not related to a typo in the settings file.

@AngelMx3 we do need a bit more information as @Colin has asked.

We have seen this error before, but it has always been due to a "bad" node being installed.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [3 July 2021 00:22 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/5 "2021-07-03T00:22:28Z")

</div>

Nick, should he be able to start in safe mode (--safe)?

---

<div class="post-metadata">

**Author:** ![eeeeuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eeeeuk/32/46094_2.png) [@eeeeuk](https://discourse.nodered.org/u/eeeeuk)\
**Post date:** [5 August 2021 12:57 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/6 "2021-08-05T12:57:14Z")

</div>

Hi did you work out how to resolve this I just upgraded node-red and on restarting I'm getting the same error message.

```auto
node-red
5 Aug 13:52:17 - [info]

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

5 Aug 13:52:17 - [info] Node-RED version: v2.0.5
5 Aug 13:52:17 - [info] Node.js version: v14.16.0
5 Aug 13:52:17 - [info] Windows_NT 10.0.18363 x64 LE
5 Aug 13:52:17 - [info] Loading palette nodes
5 Aug 13:52:17 - [error] Failed to start server:
5 Aug 13:52:17 - [error] TypeError: Cannot read property 'forEach' of undefined
    at Object.addModule (C:\Users\blah\AppData\Roaming\npm\node_modules\node-red\node_modules\@node-red\registry\lib\registry.js:195:27)
    at C:\Users\blah\AppData\Roaming\npm\node_modules\node-red\node_modules\@node-red\registry\lib\loader.js:153:34

```

---

<div class="post-metadata">

**Author:** ![eeeeuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eeeeuk/32/46094_2.png) [@eeeeuk](https://discourse.nodered.org/u/eeeeuk)\
**Post date:** [5 August 2021 13:01 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/7 "2021-08-05T13:01:16Z")

</div>

i tried to restart with node-red --safe and get the same problem

---

<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:** [5 August 2021 13:47 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/8 "2021-08-05T13:47:50Z")

</div>

What about the other questions that were asked on this thread? This error is always caused by a 'bad' node you have installed. I must admit I thought we'd squashed it once and for all in 2.x.

If you can identify what contrib node you've installed that is causing this, I'd love to see why it keeps escaping our attempts to handle it properly.

---

<div class="post-metadata">

**Author:** ![eeeeuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eeeeuk/32/46094_2.png) [@eeeeuk](https://discourse.nodered.org/u/eeeeuk)\
**Post date:** [5 August 2021 14:00 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/9 "2021-08-05T14:00:39Z")

</div>

Apologies I've installed the product to start learning... not sure what a contrib node is? I'd tried earlier to install the rabbitmq package from within the node red application - this one I think amqp-ts.

I got a warning during the installation about compatibility so thought it would be a good idea to make sure i was on the latest node-red version.

---

<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:** [5 August 2021 14:15 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/10 "2021-08-05T14:15:18Z")

</div>

> [@eeeeuk](#):
>
> I'd tried earlier to install the rabbitmq package from within the node red application - this one I think amqp-ts.

What was the full name of the package you installed? It was likely `node-red-contrib-<something>` - hence what we call `contrib` nodes.

---

<div class="post-metadata">

**Author:** ![eeeeuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eeeeuk/32/46094_2.png) [@eeeeuk](https://discourse.nodered.org/u/eeeeuk)\
**Post date:** [5 August 2021 14:30 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/11 "2021-08-05T14:30:29Z")

</div>

this one: [node-red-contrib-amqp (node) - Node-RED](https://flows.nodered.org/node/@node-red-tools/node-red-contrib-amqp) and I installed it from within the manage pallette. install

---

<div class="post-metadata">

**Author:** ![eeeeuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eeeeuk/32/46094_2.png) [@eeeeuk](https://discourse.nodered.org/u/eeeeuk)\
**Post date:** [5 August 2021 18:28 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/12 "2021-08-05T18:28:08Z")

</div>

ok... i fixed it. I added the debug that @knolleary had suggested in another post. [Error loading node-red - #2 by Steve-Mcl](https://discourse.nodered.org/t/error-loading-node-red/47219/2)

and it told me the following on start-up:

```auto
Path: C:\Users\<username>\.node-red\node_modules\node-red-contrib-amqp

```

I deleted that folder and everything in it... now starts up ok.

---

<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:** [5 August 2021 19:37 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/13 "2021-08-05T19:37:18Z")

</div>

If you don't properly uninstall it then npm will reinstall it at some point.

Go to your .node-red folder and run  
`npm remove node-red-contrib-amqp`

---

<div class="post-metadata">

**Author:** ![eeeeuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eeeeuk/32/46094_2.png) [@eeeeuk](https://discourse.nodered.org/u/eeeeuk)\
**Post date:** [6 August 2021 07:34 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/14 "2021-08-06T07:34:35Z")

</div>

thanks @Colin I'd already run the remove command but the files were still there. The debug helped me find the left-over files as initially, I'd been looking in a different directory structure.  
Hopefully that means its gone now

---

<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:** [6 August 2021 08:05 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/15 "2021-08-06T08:05:48Z")

</div>

> [@eeeeuk](#):
>
> I'd already run the remove command but the files were still there

Something went wrong with the remove then. To make sure all is as it should be go into your .node-red folder and run `npm install` and make sure it doesn't reinstall anything.

---

<div class="post-metadata">

**Author:** ![eeeeuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eeeeuk/32/46094_2.png) [@eeeeuk](https://discourse.nodered.org/u/eeeeuk)\
**Post date:** [6 August 2021 12:13 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/16 "2021-08-06T12:13:33Z")

</div>

thanks, i've run it and got this output:

```auto
\.node-red>npm install
npm notice created a lockfile as package-lock.json. You should commit this file.
removed 21 packages in 0.52s
found 0 vulnerabilities

```

seems odd that it removed packages for an install. Is that it tidying up further? Is there a way of checking what is installed with npm. To my knowledge I've only ever installed node-red and the amqp contrib that seems to have caused the problem with restarts.

---

<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:** [6 August 2021 14:14 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/17 "2021-08-06T14:14:19Z")

</div>

How have you been installing packages so that you did not have a package lock file?

---

<div class="post-metadata">

**Author:** ![eeeeuk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eeeeuk/32/46094_2.png) [@eeeeuk](https://discourse.nodered.org/u/eeeeuk)\
**Post date:** [6 August 2021 14:55 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/18 "2021-08-06T14:55:06Z")

</div>

sorry @Colin not sure i understand the question.

Initially I installed node-red just following the instructions on the site: [Running Node-RED locally : Node-RED](https://nodered.org/docs/getting-started/local)

The package that seems to have broken things I installed using the "manage pallette" option:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/0/c02b87ea7ce3a99b2a2fa067c300c9b363748601.png)

and:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/953be236c8a801293a3765b609302afe3d4922cf.png)

---

<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:** [6 August 2021 14:59 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/19 "2021-08-06T14:59:03Z")

</div>

By running `npm install`, npm uses your package.json file as the list of what should be installed. Any modules not listed in your package.json file, or not in the dependency tree of the listed modules, will get removed.

Because you removed the amqp module by deleting it's folder, you would have left behind all of its dependencies. Those will be the modules it reported as removed when you ran npm install.

---

<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:** [6 August 2021 15:35 UTC](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953/20 "2021-08-06T15:35:11Z")

</div>

I would have expected amqp to have still been in package.json and I would have expected the lock file to already exist.

[Next page](https://discourse.nodered.org/t/typeerror-cannot-read-property-foreach-of-undefined/47953.md?page=2)
