tsc --watch doesn't work in docker container
calanchue opened this issue ยท 7 comments
Bug Report
๐ Search Terms
watch container
๐ Version & Regression Information
- I have conducted testing under Typescript 5.0.4.
- Environment for testing:
- Windows 11:
tsc --watch
functioned correctly. - Host mahicne Windows11, Docker container
node:20
->tsc --watch
was unsuccessful - Host mahicne Windows11, Docker container
mcr.microsoft.com/devcontainers/typescript-node:0-20
->tsc --watch
didn't work either- vscode devcontainer image from Microsoft, designed for developing with Typescript
- Windows 11:
โฏ Playground Link
this is not about code.
๐ป Code
this is not about code
๐ Actual behavior
It appears that tsc
is unable to detect file changes in the container.
- run
tsc --watch
- Initially, it ran without any issues and produced the following output.
[12:43:12 AM] Starting compilation in watch mode... [12:43:18 AM] Found 0 errors. Watching for file changes. ``
- make change in ts files which should be compile
- nothing happens. no changes in the js output
- make change in ts files which makes error
- nothing happens. doesn't show error message
๐ Expected behavior
it works fine with my windosw11
- Initially, it ran without any issues and produced the following output.
[12:43:12 AM] Starting compilation in watch mode...
[12:43:18 AM] Found 0 errors. Watching for file changes.
- Made changes in the TypeScript files, which were required to be compiled.
- Verified that the changes were reflected in the corresponding JavaScript files.
- Introduced an error by making further changes in the TypeScript files.
- Confirmed that the error message was displayed appropriately.
[์ค์ 9:53:48] File change detected. Starting incremental compilation... src/app.ts:19:5 - error TS1440: Variable declaration not allowed at this location. 19 let's make syntax error ~~~ src/app.ts:19:5 - error TS2304: Cannot find name 'let'. 19 let's make syntax error ~~~ src/app.ts:19:28 - error TS1002: Unterminated string literal. 19 let's make syntax error [์ค์ 9:53:48] Found 3 errors. Watching for file changes.
Are you changing files that are located inside of docker container or mounted from host system?
In later case I don't think that mounts provide reliable file change notifications so most watchers would break.
If your OS isn't providing watch events, then you can use a polling based watch strategy in your TS config or command line: https://www.typescriptlang.org/tsconfig#watchOptions
The issue originated from a binding mount with the Windows host filesystem.
As advised by @RyanCavanaugh , the polling method can also be used.
In my case, I resolved the problem by moving the files to the WSL2 file system. I first created the project on the WSL2 file system, then mounted the directory to the container. This allowed for tsc --watch
to function as expected. Additionally, the WSL2 filesystem can be directly accessed (\\wsl2$
) by the Windows file browser, resulting in a seamless experience for me.
I have the same problem on Windows. Watch won't work for files in src
even if I change them inside the container itself (i.e. using vscode or the shell).
There is a lot of confusion about bind mounts on Windows: do the bind mount completly screw the watch functionality of all tools relying on watch events (TypeScript, Rollup, and many more...)... when editing from withing the container and Windows itself?
Same here, currently using a nodejs devcontainer with vscode, and npx tsc --watch
don't detect any change....
I'm running Node inside Docker on my Windows computer, and configuring these settings fixed the issue for me.
"watchOptions": {
"watchFile": "dynamicPriorityPolling"
}