Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): use optional-require dependency #1736

Merged
merged 2 commits into from
Apr 15, 2021

Conversation

balazsorban44
Copy link
Member

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 of require_optional first, as the latter looks to be unmaintained (with still a number of downloads/week though), and even the mondodb 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:

  • Documentation
  • Tests
  • Ready to be merged

@vercel
Copy link

vercel bot commented Apr 15, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nextauthjs/next-auth/GLavhMbV1NMZXN74txpwaqAFp3PL
✅ Preview: https://next-auth-git-fix-use-optional-require-dep-nextauthjs.vercel.app

@balazsorban44 balazsorban44 changed the title Fix/use optional require dep fix: use optional-require dependency Apr 15, 2021
@github-actions github-actions bot added adapters Changes related to the core code concerning database adapters core Refers to `@auth/core` providers labels Apr 15, 2021
@balazsorban44 balazsorban44 changed the title fix: use optional-require dependency fix(build): use optional-require dependency Apr 15, 2021
@balazsorban44 balazsorban44 merged commit 9fa93e3 into next Apr 15, 2021
@balazsorban44 balazsorban44 deleted the fix/use-optional-require-dep branch April 15, 2021 22:23
@github-actions
Copy link

🎉 This PR is included in version 4.0.0-next.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@balazsorban44
Copy link
Member Author

balazsorban44 commented Apr 15, 2021

DISCLAIMER: Did not seem to work as expected... I will keep exploring ways that will make typeorm and nodemailer truly optional, so we can drastically reduce bundle size for those not using any of them.

mnphpexpert added a commit to mnphpexpert/next-auth that referenced this pull request Sep 2, 2024
* chore(deps): add optional-require

* refactor: use optional-require
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Changes related to the core code concerning database adapters core Refers to `@auth/core` providers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant