Skip to content

Regression - TypeScript watch attempts to watch parent directory files  #24434

@jack-guy

Description

@jack-guy

TypeScript Version: 3.0.0-dev.20180526

Search Terms: TypeScript, Watch, Hang

Code

Repo with reproduction

Steps

  1. clone repository
  2. cd linked-package, yarn, tsc
  3. cd main, yarn
  4. Add breakpoints to watchFailedLookupLocationOfResolution, run compiler in watch mode in /main to see that the values of dir and dirPath will cause watchers to be added to files in the reproduction directory, including the unrelated-package folder. I do this using vscode - here's a demonstration video.

I haven't been able to exactly narrow down what is causing this behavior, but it seems to have a few necessary components:

  1. A symlinked module dependency
  2. That symlinked module dependency exports from another file
  3. That symlinked module has a scoped name (e.g. @scoped/linked-package) - less sure about this one

Expected behavior:
In TypeScript 2.7, watchers aren't added for this parent directory. This behavior is introduced in TypeScript 2.8 and remains in the latest 3.0 versions.

There shouldn't be a module lookup failure in this case and file watchers should not be added outside the confines of the directory where the compiler is run.

Actual behavior:
I first discovered this behavior when running Typescript 2.8 on a pretty large project of mine. While the build was completing without issue, when I tried to watch for changes the CLI got stuck on "Starting compilation in watch mode..."

I diagnosed the issue by issuing a SIGUSR1 to the typescript process to start a debugger and found that TypeScript was adding file watchers to all the directories in foo/ where my project was in foo/a/ and used a module foo/b/. Since foo/ is my personal development directory with many, many JavaScript projects, the compiler was effectively hanging indefinitely.

I noticed that if I remove the symlinked module's export and inlined its code (in the reproduction export * from './other';), the module lookup no longer fails.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions