Cyclic dependencies are broken with module instance objects
See original GitHub issueThe following code works fine:
// a.js
import {b} from "./b.js";
export function a() {
console.log(b);
}
//b.js
import {a} from "./a.js";
export function b() {
console.log(a);
}
But if we rewrite this using module instance objects the compiler iloops:
// a.js
import * as m from "./b.js";
export function a() {
console.log(m.b);
}
//b.js
import * as m from "./a.js";
export function b() {
console.log(m.a);
}
And here is the part of the stack trace that keeps getting called over and over again.
...
at com.google.javascript.jscomp.modules.EsModuleProcessor$UnresolvedEsModule.resolve(EsModuleProcessor.java:318)
at com.google.javascript.jscomp.modules.EsModuleProcessor$UnresolvedEsModule.resolveImportImpl(EsModuleProcessor.java:415)
at com.google.javascript.jscomp.modules.EsModuleProcessor$UnresolvedEsModule.resolveImport(EsModuleProcessor.java:378)
at com.google.javascript.jscomp.modules.EsModuleProcessor$UnresolvedEsModule.resolveImport(EsModuleProcessor.java:385)
at com.google.javascript.jscomp.modules.EsModuleProcessor$UnresolvedEsModule.getAllResolvedImports(EsModuleProcessor.java:360)
at com.google.javascript.jscomp.modules.EsModuleProcessor$UnresolvedEsModule.resolve(EsModuleProcessor.java:318)
at com.google.javascript.jscomp.modules.EsModuleProcessor$UnresolvedEsModule.resolveImportImpl(EsModuleProcessor.java:415)
at com.google.javascript.jscomp.modules.EsModuleProcessor$UnresolvedEsModule.resolveImport(EsModuleProcessor.java:378)
at com.google.javascript.jscomp.modules.EsModuleProcessor$UnresolvedEsModule.resolveImport(EsModuleProcessor.java:385)
at com.google.javascript.jscomp.modules.EsModuleProcessor$UnresolvedEsModule.getAllResolvedImports(EsModuleProcessor.java:360)
...
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How to deal with cyclic dependencies in Node.js
Try to set properties on module.exports , instead of replacing it completely. E.g., module.exports.instance = new ClassA() in a.js ...
Read more >How to Eliminate Circular Dependencies from Your JavaScript ...
Circular dependencies (also known as cyclic dependencies) occur when two or more modules reference each other.
Read more >How to fix nasty circular dependency issues once and for all in ...
First, this is ugly and doesn't scale. In a large code base, this will result in moving imports randomly around until stuff just...
Read more >Allow circular dependencies in resources · Issue #27188 ...
This is a circular dependency in Terraform, regardless of provider/platform, since you cannot have their resource objects reference each other unless they ...
Read more >How to solve this basic ES6-module circular dependency ...
The module system does execute all a module's dependencies before executing that module, except in cases like this where there are cycles in...
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 FreeTop 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
Top GitHub Comments
Just to update: I’ve not really had time to look at this, or so I thought. I was over-complicating a solution, but I think there’s a simpler one. Fix should be out soon.
Thanks, I’ll take a look!