NodeJS : How to debug “EventEmitter memory leak detected. 11 listeners added”

前端 未结 8 565
攒了一身酷
攒了一身酷 2020-11-28 20:23

How can I debug my application which throw this error:

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxList         


        
8条回答
  •  臣服心动
    2020-11-28 20:57

    I ran into the same problem when testing React components using mocha and enzyme.

    I was able to solve my problem by explicitly unmounting components after I had finished testing them.

    The issue was that I was mounting components multiple times in my tests, which were then adding more listeners, until the number of listeners got to 11, and I got a warning.

    I changed my test code by adding the rendered.unmount() line. This fixed the problem for me.

    describe('', () => {
    
        it('renders', function () {
            const rendered = mount();
            assert.ok(rendered.find('path'));
            rendered.unmount();
        });
    }
    

提交回复
热议问题