Endless recursion on circular dependencies
See original GitHub issueHello,
I have an issue when using clear-module within a Mocha unit test: I get an endless recursion. However if I run it outside of a test I don’t.
I have successfully used clear-module in tests before. It looks to be related to:
- upgrading to clear-module: “4.1.0” as the example below works with “3.1.0”
- clearing sshpk as this has circular dependencies defined
This works fine:
// demo.js
require('sshpk');
const clearModule = require('clear-module');
console.log('before');
clearModule('sshpk');
console.log('after');
produces:
% node demo.js
before
after
However if I run using mocha, it hangs on the call to clearModule:
require('sshpk');
const clearModule = require('clear-module');
console.log('before');
clearModule('sshpk');
console.log('after');
describe('yyy', () => {
it('xxx', function () {
});
});
produces:
% ./node_modules/.bin/mocha test/services/demo.spec.js
before
When I debug this I can see an endless recursion of clearing the sshpk modules which have a circular reference.
I am using node 12.6.0 and the following lib versions:
- “mocha”: “7.1.0”
- “clear-module”: “4.1.0” (previously 3.1.0 which worked)
- “sshpk”: “1.16.1”
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Circular Dependencies - Endless Recursion #269 - GitHub
My idea is to move the value generation from generate_value(name, params) into their adequate Generator (e.g. Fabrication::Generator:: ...
Read more >Value-equals and circular references: how to resolve infinite ...
Like you said, a infinite recursion can happen in circle of X length (example: after the 10 iteration it's pointing to the 2nd...
Read more >Breaking Circular Dependencies in Recursive Union Types ...
A value itself is either a string, a number, true, false, null, or again an array or an object. Note the recursive structure...
Read more >Circular dependencies - The Apache Software Foundation!
In software, a circular dependency is a relation between two or more classes ... a circular dependency can generate an infinite recursion leading...
Read more >Catching circular references in parent-child structures
Now, if we say that “E” is the parent of “3”, we've created a circular reference, and we end up with an infinite...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Confirmed fixed for me - thanks!
I have reproduced the issue with the following steps:
create a new npm project and install
mocha,sshpk,clear-moduleCreate a test file
#14 should definitely resolve this issue