vitest-dev / vitest-dev/vitest

[vite-node] Watch mode breaks with circular imports

Open
#4,904 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

pending triage
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.