How does one dynamically import optional dependencies? #18027
|
I cannot either figure it out from the docs or from other sources online the answer to this question: How can I dynamically import a package (eg. I am building a library which has optional features that dynamically import the optional peer dependencies. The app consuming my library tries to build with webpack. But this will result in the build failing with import('abc')
.then(/* the peer dep is there */)
.catch(/* do something in case the optional peer dep isn't there*/)This seems like an obvious use-case to me, since package managers allow one to express the requirement of an optional peer dependency. Am I having a wrong expectation? I know that some libraries take the approach of exposing a different entry point for the optional feature but that's besides the point, because that doesn't relate to dynamic imports. I also know that this works if one wants to require the package in a try...catch, but that's also besides the point. (and not feasible in my case anyway) |
Replies: 1 comment 19 replies
|
Please read #11874, shortly - your browser versions (in browserslist or in the |
https://github.com/webpack/webpack/releases/tag/v5.90.2