-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
TypeScript Version: 3.0.0-dev.20180526
Search Terms: TypeScript, Watch, Hang
Code
Steps
- clone repository
- cd linked-package, yarn, tsc
- cd main, yarn
- Add breakpoints to
watchFailedLookupLocationOfResolution, run compiler in watch mode in/mainto see that the values ofdiranddirPathwill cause watchers to be added to files in thereproductiondirectory, including theunrelated-packagefolder. 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:
- A symlinked module dependency
- That symlinked module dependency exports from another file
- 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.