question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cyclic dependencies are broken with module instance objects

See original GitHub issue

The 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:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jplaistedcommented, May 2, 2019

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.

1reaction
jplaistedcommented, Apr 9, 2019

Thanks, I’ll take a look!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found