preact-lazy-route
preact-lazy-route copied to clipboard
Webpack: Critical dependency: the request of a dependency is an expression
When bundling with webpack, you may come across the error:
Critical dependency: the request of a dependency is an expression
This is due to the dynamic require being used for server-side rendering. Since that require should never be utilized when bundling in webpack, we should not include that require for analysis when webpack is being used.
I believe it would be nicer if the API was like this, and it would solve the problem with Critical dependency.
<LazyRoute path="/" component={() => import('./home')} ssr={() => require('./home')} />