Circular dependency warning despite dynamic import
See original GitHub issueDescribe 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top 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 >
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
Fixed by #3950
closing as pr got merged and after test of reproduction it seems to be printing as expected according to conversation