fix(build): use optional-require dependency #1736
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What:
Use
optional-require
to require certain modules optionally.Why:
To my sadness, after trying out #1682 on a local project, I discovered that Next.js Webpack will try to include modules in the dev/prod builds that were added through dynamic imports, **even though they are wrapped in a conditional that is never
true
.*. That just seem to be a limitation/behaviour I do not understand fully, to be honest. If someone visits this PR, please enlighten me 💡, or show me to some documentation/reasoning! In the meantime, let's see that using a wrapper for importing helps.I am trying
optional-require
instead ofrequire_optional
first, as the latter looks to be unmaintained (with still a number of downloads/week though), and even themondodb
module (that we used as an example when implementing optional modules) switched from it, as it introduced a bug in Windows.How:
Switch out the failed dynamic imports to
optionalRequire
calls, and see if solves the problem.Checklist: