vitest-dev / vitest-dev/vitest
[vite-node] Watch mode breaks with circular imports
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 94
Description
Describe the bug
When running vite-node with -w flag on files that have circular imports it doesn't restart the code when any of the files change. My project relied on this behaviour for a while, but when I updated from version 0.32.2 to 0.34.6 (and later) it broke
Reproduction
a.ts
import { exportFromB } from "./b";
export const exportFromA = "A";
setTimeout(() => console.log(exportFromB));
b.ts
import { exportFromA } from "./a";
export const exportFromB = "B";
setTimeout(() => console.log(exportFromA));
Run npx vite-node -w a.ts, change any file -> nothing happens.
System Info
System:
OS: macOS 13.4.1
CPU: (8) arm64 Apple M1
Memory: 160.00 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 21.5.0 - /opt/homebrew/bin/node
npm: 10.2.4 - /opt/homebrew/bin/npm
pnpm: 8.14.0 - ~/Library/pnpm/pnpm
bun: 1.0.21 - ~/.bun/bin/bun
Browsers:
Brave Browser: 120.1.61.114
Safari: 16.5.1
Used Package Manager
pnpm
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.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running npx vite-node -w a.ts with the circular-import reproduction in a.ts and b.ts, then change either file. Trace the watch-mode entry point and its handling of the circular dependency graph; done means changes to either file reliably restart the code, with a regression test covering this reproduction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100