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.

Circular dependency warning despite dynamic import

See original GitHub issue

Describe the bug

Suppose I have two files like these:

// one.mjs
console.log("Hello from one.mjs");

setTimeout(() => {
	import("./two.mjs");
}, 500);
// two.mjs
import "./one.mjs";

console.log("Hello from two.mjs");

When I ssrLoadModule("./one.mjs"), I get the following output:

Hello from one.mjs
Hello from one.mjs
Hello from two.mjs
Circular dependency: one.mjs -> /two.mjs -> /one.mjs -> /two.mjs

That is, one.mjs is evaluated twice before two.mjs is evaluated and I get a circular dependency warning. I’m aware of the limitations and I know there is a pull request to allow circular dependencies in SSR.

But in this case I think the evaluation of one.mjs should have been completed before two.mjs is imported due to the timeout. So this shouldn’t count as a circular dependency but Vite disagrees.

Reproduction

  • Clone this repo
  • Install dependencies with npm ci
  • Run with npm start

System Info

System:
    OS: Linux 5.4 Linux Mint 20.2 (Uma)
    CPU: (8) x64 Intel(R) Core(TM) i7-3630QM CPU @ 2.40GHz
    Memory: 370.95 MB / 15.53 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 12.22.1 - /usr/local/bin/node
    Yarn: 1.22.10 - ~/.npm-global/bin/yarn
    npm: 7.19.1 - ~/.npm-global/bin/npm
  Browsers:
    Chrome: 91.0.4472.164
    Firefox: 90.0
  npmPackages:
    vite: ^2.4.2 => 2.4.2

Used Package Manager

npm

Logs

No response

Validations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
aleclarsoncommented, Jul 18, 2021

but the circular dependency warning remains

Fixed by #3950

0reactions
Niputicommented, Oct 31, 2021

closing as pr got merged and after test of reproduction it seems to be printing as expected according to conversation

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
What happens when using mutual or circular (cyclic) imports?
Cyclic imports terminate, but you need to be careful not to use the cyclically-imported modules during module initialization.
Read more >
How to solve this basic ES6-module circular dependency ...
The reason why I'm after a solution for the circular dependency is because in my real-world case I need to use instanceof A...
Read more >
@carbon/charts-svelte - npm
Circular dependency warnings. You may see circular dependency warnings for d3 and @carbon/charts packages that can be safely ignored.
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. ... // file a.ts import { b...
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