Replies: 1 comment 8 replies
-
Please read #11874, shortly - your browser versions (in browserslist or in the |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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.
import('abc')
) which is an optional peer dependency?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
ModuleNotFoundError
if the optional peer dependency isn't there. But since the dependency is optional (defined inpackage.json
) this is wrong. If I instruct webpack to ignore the import with a magic comment then the dependency isn't bundled in case it's there, so it will always be missing. I just can't find the middle ground where I can just: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)
Beta Was this translation helpful? Give feedback.
All reactions