You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Watcher doesn't see a new file until restart #6262
This is caused by the "unsafe" resolver cache. You can disable the cache with resolve.unsafeCache: false but this has very negative impact on performance.
Is there any middle ground or a heuristic we could use? For example, if a file is not found, then invalidate any cache entries around it on any FS event.
Reacted by Prateek Jain, Ihor Yemets, Brenton Partridge, Chang Wang and Rhys van der Waerden
This seems to be the same root issue as #5523, and we're running into it as well when gradually refactoring a codebase (in our case, the watcher starts reporting ENOENT when you rename x.js to x.ts or similar).
It seems that this is where the cache entry is saved (the resolve.unsafeCache setting is what determines the cachePredicate):
Perhaps one way to achieve this with a minimal performance overhead would be to have a synchronous plugin tap immediately after a cache entry is read or created? Then a new plugin, only enabled during dev (and perhaps enabled by default?), could then:
run an asynchronous NodeFileWatcher
maintain a weak trie of the cache entries
mark parts of that trie as invalidated when a filesystem change is detected
quickly check the trie synchronously before returning a module from cache (i.e. "check-cache-entry-validity" as a plugin tap point)
This way you wouldn't need to completely turn off the caching, and overhead would be minimal - no need to go out to every resolver out there. And once the API hooks are inserted, the proposed plugin could be developed in a separate repository to meet all these edge cases, so that ongoing webpack core development isn't affected.
Am I missing anything here? Any reason not to try this approach?
Also suffering from this issue at present while slowly migrating from JS to TS. Branch changes are particularly annoying as they nearly always involve renames. I tried to unsafeCache: false and it didn't appear to work (although I'm not sure if this might be a symptom of other plugins or configuration).
Actually after spending few hours on this, I'm quite sure unsafeCache option is actually in both resolve and in module section of configuration. Second place is undocumented.
And it can be actually a function and then it is a predicate.
Maybe I'm not aware of sth, otherwise it's quite confusing in the docs, I can create a PR if it's the case ?
I am going to hop on the train and mention it really slows down my developement since no changes detected causes the need to restart and open new server for my react-app each time I run into this.
Activity
sokra commentedon Jan 8, 2018
This is caused by the "unsafe" resolver cache. You can disable the cache with
resolve.unsafeCache: falsebut this has very negative impact on performance.gaearon commentedon Jan 8, 2018
Is there any middle ground or a heuristic we could use? For example, if a file is not found, then invalidate any cache entries around it on any FS event.
bpartridge commentedon Jan 13, 2018
This seems to be the same root issue as #5523, and we're running into it as well when gradually refactoring a codebase (in our case, the watcher starts reporting ENOENT when you rename x.js to x.ts or similar).
It seems that this is where the cache entry is saved (the
resolve.unsafeCachesetting is what determines thecachePredicate):webpack/lib/NormalModuleFactory.js
Lines 239 to 240 in f352436
And the cache entry is read here:
webpack/lib/NormalModuleFactory.js
Lines 214 to 216 in f352436
Perhaps one way to achieve this with a minimal performance overhead would be to have a synchronous plugin tap immediately after a cache entry is read or created? Then a new plugin, only enabled during dev (and perhaps enabled by default?), could then:
This way you wouldn't need to completely turn off the caching, and overhead would be minimal - no need to go out to every resolver out there. And once the API hooks are inserted, the proposed plugin could be developed in a separate repository to meet all these edge cases, so that ongoing webpack core development isn't affected.
Am I missing anything here? Any reason not to try this approach?
rhys-vdw commentedon Feb 14, 2018
Also suffering from this issue at present while slowly migrating from JS to TS. Branch changes are particularly annoying as they nearly always involve renames. I tried to
unsafeCache: falseand it didn't appear to work (although I'm not sure if this might be a symptom of other plugins or configuration).ZuBB commentedon Feb 15, 2018
I may be wrong but looks like next PR should fix this #6451
would be nice to get some confirmation of my guess from core team/major contributors..
wujashek commentedon Feb 28, 2018
Actually after spending few hours on this, I'm quite sure unsafeCache option is actually in both resolve and in module section of configuration. Second place is undocumented.
At least for v3.x,
And it can be actually a function and then it is a predicate.
Maybe I'm not aware of sth, otherwise it's quite confusing in the docs, I can create a PR if it's the case ?
soda-x commentedon Jul 31, 2018
same issue here
Lukortech commentedon Aug 27, 2019
I am going to hop on the train and mention it really slows down my developement since no changes detected causes the need to restart and open new server for my react-app each time I run into this.
sokra commentedon Aug 27, 2019
webpack 5 has this problem fixed
minimit commentedon Nov 21, 2019
In webpack 5 it's not fixed when using multiple aliases #10015
raminrez commentedon Dec 22, 2019
@gaearon @minimit we have the same issue when using multiple aliases
minimit commentedon Dec 22, 2019
it's getting worked on webpack 5 #9802 (comment)
vankop commentedon Aug 9, 2020
Should work with
webpack@next. Feel free to report new issue with reproducible repo.