Skip to content
New issue

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

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

Already on GitHub? # to your account

Unexpected watcher stops #465

Closed
deftomat opened this issue Nov 23, 2018 · 7 comments · Fixed by #489
Closed

Unexpected watcher stops #465

deftomat opened this issue Nov 23, 2018 · 7 comments · Fixed by #489
Milestone

Comments

@deftomat
Copy link

deftomat commented Nov 23, 2018

We are using fork-ts-checker-webpack-plugin to run TypeScript checks in watch mode.

This plugin starts TypeScript in watch mode in a separate process. It needs to know, when user stops the webpack's watcher to be able to stop TypeScript service. So, it is listening to watchClose hook.

However, #319 introduce a watcher stop/start after each recompilation. This leads to killing the TS service and starting it again. See https://github.com/Realytics/fork-ts-checker-webpack-plugin/blob/5f5d967e07c7da0e860b6854857da145c33c7c0f/src/index.ts#L296.

The problem is, that type-check can easily took 5-6 seconds for the first run and less than 200ms after recompilation. However, this stop/start behavior causes that it always starts from scratch.

So, my question is: Are we able to avoid stoping the watcher? I'm pretty sure that other webpack plugins can depend on it too. Also, fork-ts-checker-webpack-plugin is basically a standard for TS projects.

EDIT:
Another issue is that sometimes recompilation occurs twice:
image

@dwelch2344, @HyperBrain

@mochja
Copy link

mochja commented Feb 20, 2019

@deftomat we are not using fork-ts-checker-webpack-plugin, but with Webpack 4 and ts-loader rebuild is triggered twice for me each time I change something.

Serverless: Offline listening on http://localhost:3000
Time: 3848ms
Built at: 2019-02-20 14:36:05
         Asset      Size   Chunks             Chunk Names
    handler.js  4.08 MiB  handler  [emitted]  handler
handler.js.map  4.26 MiB  handler  [emitted]  handler
Entrypoint handler = handler.js handler.js.map
[0] multi ./handler.ts 28 bytes {handler}
[./app.config.ts] 315 bytes {handler}
[./handler.ts] 3.87 KiB {handler}
    + 762 hidden modules
Time: 2727ms
Built at: 2019-02-20 14:36:07
         Asset      Size   Chunks             Chunk Names
    handler.js  4.08 MiB  handler  [emitted]  handler
handler.js.map  4.26 MiB  handler  [emitted]  handler
Entrypoint handler = handler.js handler.js.map
[0] multi ./handler.ts 28 bytes {handler}
[./app.config.ts] 315 bytes {handler} [built]
[./handler.ts] 3.87 KiB {handler} [built]
    + 762 hidden modules
Serverless: Watching for changes...
Serverless: Watching for changes...

did you happen to find solution for that?

@mochja
Copy link

mochja commented Feb 20, 2019

I think this is related to webpack/webpack#4991.

const watcher = compiler.watch(watchOptions, (err, stats) => {

compiler.watch is triggering build first and then it's waiting for changes. So each time startWatch is exectuted, build it triggered first.

@deftomat
Copy link
Author

deftomat commented Feb 21, 2019

@mochja Hi, we are using a custom fork as it looks like the project is not maintained anymore.

This is a commit which fixed it for us: deftomat@839d2e5

@livingmine
Copy link

@mochja @deftomat rebuild also triggered twice on my project. One thing i notice is that this line on wpwatch.js is never true

if (stats && stats.hash === lastHash) {

stats.hash and lastHash is always different. On a normal working project where this problem does not occur, that expression should be evaluated to true and acts as a terminal point of our watcher while it is waiting for the next changes.

On a troubled project however, it is as if there is another source of changes triggering the another new process which i'm still looking for.

@mochja
Copy link

mochja commented Mar 23, 2019

We have stopped using webpack for development and instead use ts directly.

node -r dotenv/config -r ts-node/register/transpile-only -r tsconfig-paths/register node_modules/serverless/bin/serverless offline

I did spend some time in debugger and there was no additional trigger in our case.

@livingmine
Copy link

@mochja Awesome! I'm actually okay with the current situation(rebuild triggered twice) as my current build process is still less than <10s but as my project grows in size i'll keep looking for the solution and might resort to your suggestion or @deftomat fork of this repo as a last resort. Thanks!

@HyperBrain HyperBrain added this to the 5.3.0 milestone Apr 7, 2019
@HyperBrain
Copy link
Member

Released with 5.3.0

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants