Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
When I build my web application using webpack, I get the following warning message: "Critical dependency: require function is used in a way in which dependencies cannot be statically extracted".
Should I worry about this? Is there any way can address the problem that is being warned-about? Does decache work in the context of webpack?
Thanks
In fact it seems that it is not just a warning: the require function is throwing an exception. It seems that decache is not going to work with webpack?
The exception is being thrown in const decache = require("decache")
Using [email protected]
@dkent600 WebPack has not been our typical use case/context for decache.
Could you please share more details? are you wanting to use decache during static asset building?
I felt wanted to use decache when the state changed in the application such that I needed to refetch certain assets that had been fetched (via require) before.
I use past tense above because I've since decided that this was, from the point of view of my application, a wrong approach. So I have abandonned the effort.
So unless you wish to pursue this use case, for my part you can close the ticket. Thanks for the followup.
@dkent600 your "second thought" intuition is a good one.
re-requiring assets in the context of an app will lead to unpredictable behaviour.
it's fine to use decache within tests to reset the state of required modules,
but in an app you'd be chasing your tail... 😉