0

After migrating my angular application from 12 to 13, whenever I am running the app, and if I refresh the page or make a network call, I am getting the below error in the node terminal.

enter image description here

My current node version is 16.16.0 (previously it was 14.17.1)

I am also using ngrx, which also I migrated to v13

Has anyone faced a similar issue, and is there any solution to this?

Thanks

nshathish
  • 417
  • 8
  • 23

3 Answers3

2

Had same problem after migrating angular 12 to 13, just figured out what was in my case, and looking at the exception it seems that in your case also. In proxy.conf.js I had 25 paths and will create a proxy instance for every "path". There is an explanation on how to configure proxy config for webpack https://webpack.js.org/configuration/dev-server/#devserverproxy.

In order to see if the problem is in proxy.conf.js I added a line like below, so I have 25 paths, set EventEmitter.defaultMaxListeners to 30 and error is not occurring anymore

Added at the beginning of proxy.conf.js

require('events').EventEmitter.defaultMaxListeners = 30;

Victor
  • 36
  • 1
  • I removed some entries from the proxy file and now I don't get any errors Thank you so much; I couldn't have figured out without your help – nshathish Aug 12 '22 at 15:31
  • but in my case I use proxy.json file, so I couldn't try above code snippet – nshathish Aug 12 '22 at 15:48
2

I faced the same issue. I had 18 paths in my old proxy.config.json, like this:

{
  "/url1": {
    "target": "https://hostname",
    "secure": false
  },

  ...

  "/url18": {
    "target": "https://hostname",
    "secure": false
  }
}

Then I changed it to this(refer to Use angular-cli with multiple path proxy matching):

[
  {
    "context": [
      "/url1",

      ...
      
      "/url18"
    ],
    "target": "https://hostname"
    "secure": false
  }
]

Then the problem disappeared.

Will Sun
  • 21
  • 2
0

For me, the solution from @Victor but with the method call the error message is exactly pointing out also worked.

You have to count your proxy rules and set that exact number. You count all the "/some/path/..": rows in your proxy.conf.js.

For me it was 13. See 13 in the method call down below.

The message:

(node:21924) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [Server]. Use emitter.setMaxListeners() to increase limit

The code I used in proxy.conf.js, which seems a bit more syntax-friendly for me:

const emitter = require('events');
emitter.setMaxListeners(13);
Janos Vinceller
  • 1,208
  • 11
  • 25