-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Optional dependency of MongoDB cannot be resolved when running in AWS using serverless component #887
Comments
This is a problem with way the app is bundled, if you include package.json in the list of files that get bundled and deployed and that should resolve the issue - I think there are some old issues (possibly closed now) that cover this. I think not using optional require has the impact of introducing problems for other users, which IIRC is why we don't do it - dynamic imports - which are the "right" way to solve this " - are still not well supported by some bundlers (not really NextAuth.js problem exactly, except that people would then log bug reports about that). I think there is more info about that in the old tickets. The error isn't great and it would be nice to have a better way of doing this that is lower friction for everyone. Splitting the SQL Adaptor from the MongoDB Adaptor (but sharing common code, like the models) is also an option and might be the best move. |
PS: Thanks for recording this and for the detail. Happy to leave this open until we have a more satisfactory resolution - either code change or documentation improvement, etc. |
As far as I understand, this also affects production builds for NextJS application, so would this mean that we can not use MongoDB in production? Would be great to have documentation updated for this. I see there is an alternative for this, is to move this piece of code into the userland, as a callback? i.e.
I created a more sane patch for webpack, see this PR for more information. |
No it's working fine for most people. |
Hi there! It looks like this issue hasn't had any activity for a while. It will be closed if no further activity occurs. If you think your issue is still relevant, feel free to comment on it to keep it open. (Read more at #912) Thanks! |
Hi there! It looks like this issue hasn't had any activity for a while. To keep things tidy, I am going to close this issue for now. If you think your issue is still relevant, just leave a comment and I will reopen it. (Read more at #912) Thanks! |
This is not work for me, I tring bild on aws amplify. I'm not using mongodb, but this erro r persists. I'm using cognito for auth. I updated already, I'm using nextjs 11, and nxt-auth 3.27.3, I tried using this dependency installed on project, typeorm, but only got fails. On build locally I not got this error.
|
Describe the bug
When using MongoDB storage adapter, the way right now it is loaded by using require_optional are not compatible with
serverless-nextjs
packaging (and I believe not really compatible with AWS Lambda ways of working).When it packaged as Lambda@Edge there is no package.json anymore.
It manifests as following error in login form: Try signing with a different account.
Also error generated in AWS CloudWatch (see below)
Steps to reproduce
Clone https://github.com/huksley/next-auth-example/tree/aws-serverless (notice aws-serverless branch)
Configure
.env.local
with at least following defined:You can get MongoDB instance from MongoDB Cloud Atlas for free.
Run once with
npx serverless
to do initial deploy and get CloudFront domain.Add
NEXTAUTH_URL=https://xxxxx.cloudfront.net
to .env.local afterwards and deploy again.Navigate to
https://xxxxx.cloudfront.net
and try to login with Google.Expected behavior
Google Login works with MongoDB storage adapter.
Screenshots or error logs
Additional context
It is working fine locally by using
npm run dev
but NOT WITHnpm run build && npm run start
It is connected with the issue discussed here: Error: no optional dependency [mongodb] defined in peerOptionalDependencies in any package.json #552
Not sure why
next-auth
needs to loadmongodb
as an optional dependency when it will clearly fail ifconfig.type == "mongodb"
Hot fixing the bug
Patching next-auth fixes this problem:
Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
The text was updated successfully, but these errors were encountered: