Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsc --watch doesn't work in docker container #54144

Closed
calanchue opened this issue May 5, 2023 · 7 comments
Closed

tsc --watch doesn't work in docker container #54144

calanchue opened this issue May 5, 2023 · 7 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@calanchue
Copy link

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

⏯ 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.
    
@IllusionMH
Copy link
Contributor

IllusionMH commented May 5, 2023

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.

@RyanCavanaugh RyanCavanaugh added the External Relates to another program, environment, or user action which we cannot control. label May 5, 2023
@RyanCavanaugh
Copy link
Member

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

@calanchue
Copy link
Author

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.

@gremo
Copy link

gremo commented Aug 15, 2023

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?

@TheMatrix97
Copy link

Same here, currently using a nodejs devcontainer with vscode, and npx tsc --watch don't detect any change....

@akbarnafisa
Copy link

I'm running Node inside Docker on my Windows computer, and configuring these settings fixed the issue for me.

  "watchOptions": {
    "watchFile": "dynamicPriorityPolling"
  }

@pjcollazo
Copy link

I'm currently having the same issue. Windows 11 host running a docker container with volume mounts.
Running tsc -w and modifying the file within IDE or the container results in no change detected.

This is with polling enabled

  "watchOptions": {
    "watchFile": "dynamicPriorityPolling"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

7 participants