I've had success resolving circular dependencies in Node by exporting the 
declaration of the model in one of the dependents before invoking the 
circular reference.  

For instance

*a.js*
var b = require('./a');

module.exports = function() {
    var _b = new b();
    _b.initialize();
};



*b.js*
var b = function() { };
module.exports = b;

var a = require('./a');

b.prototype.initialize = function() {
    var _a = new a();
}

Of course the above code example would lead to some serious stack overflow 
problems, but the point is, NodeJS shouldn't fail on it just because of the 
circular dependency.  

With your specific case, you might be able to apply some of the same logic 
to the port that you're attempting to accomplish. 

Good luck. 


On Thursday, January 12, 2017 at 7:53:38 AM UTC-7, Gautham B A wrote:
>
> Hi all,
>
> I'm trying to port a nodejs module called "sweet.js" into v8. I'm doing 
> this by resolving the dependencies. Specifically, I'm replacing the calls 
> to "require()" method of a module by replacing it with the actual code of 
> the dependency.
> e.g. Contents of "a.js"
> var b=require('./b');
>
> Contents of "b.js"
> function(){
>  console.log('inside b');
> }
>
> Now I replace the contents of "a.js" as -
> var b=(function(){
>              console.log('inside b');
>             });
>
> However, I got stuck when I tried to resolve circular dependencies. 
> "require()" somehow takes care of resolving circular dependencies 
> "silently" as it says in the docs.
> Could anyone please shed some light regarding this?
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/79cb9843-0850-4ead-a23b-054d6b9995a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to