-
-
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
Error: no optional dependency [mongodb] defined in peerOptionalDependencies in any package.json #552
Comments
Hi there! Hmm that's odd. It would be appreciate if you could share a link to a repo to replicate this issue. I wonder if it's related to a custom webpack or babel config that is maybe doing something odd (or possibly a typo in an import statement somewhere?) |
thanks for answering. Can I add you to the repo? EDIT: at the time posting the link I tried it and asked a friend to try it too and we both were seeing the error. I just tried it again and don't see it 🤔 |
I have the same issue:
|
I'm also experiencing the same issue:
|
FYI, I didn't see this issue for 2 days and now I'm seeing it again. Didn't change any back end code though. But I noticed that 1 minute before seeing this error I got this one: MongooseServerSelectionError: connection <monitor> to 127.0.0.1:27017 closed
at NativeConnection.Connection.openUri (/Users/mati/Development/annotations/node_modules/mongoose/lib/connection.js:827:32)
at Mongoose.connect (/Users/mati/Development/annotations/node_modules/mongoose/lib/index.js:335:15)
at dbConnect (webpack-internal:///./utils/dbConnect.js:12:68)
at handler (webpack-internal:///./pages/api/annotations/index.js:28:73)
at runMicrotasks (<anonymous>)
message: 'connection <monitor> to 127.0.0.1:27017 closed',
reason: TopologyDescription {
type: 'Single',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map { 'localhost:27017' => [ServerDescription] },
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
} not sure if it's related |
Please share link to public repository or steps to replicate including versions (Nodejs, npm, etc.). |
I have this error too |
I got this, let's see in the Warning https://next-auth.js.org/providers/google |
I think I fixed it, just need delete package.lock and node modules then run |
I cannot replicate this with the example project and am not seeing this issue on other projects. If you are experiencing a problem please provide an example with steps to replicate. |
I faced this issue also even if I removed mongodb and install it again the error will appears again
to remove the mongodb
it will appears on the package.json like that
|
FYI, I've removed |
unfortunately this works for some hours and the error back again
with or without |
Yeah, I just got the error again after doing the I know it's not possible to get an answer without posting a project to reproduce it. I'm just posting this here for the rest of us having the same issue. BTW, @alsemany how are you connecting to mongo? I'm using the dbConnect example: import mongoose from 'mongoose'
const connection = {}
async function dbConnect() {
if (connection.isConnected) {
return
}
const db = await mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
// useUnifiedTopology: true,
useFindAndModify: false,
})
connection.isConnected = db.connections[0].readyState
}
export default dbConnect |
For context, the error is from this line in the NextAuth.js uses this package to load MongoDB when a MongoDB database is specified, so it can load the ObjectID type. The Given three people who reported this have now cited a path of It's hard to say for sure without code to replicate this, but we might be at something of an impasse between people who can't use (I can think of a way to address it for both groups, but it would be a breaking change and one I would rather avoid.) It would be interesting to know if Adding "peerOptionalDependencies": {
"mongodb": "^3.6.0"
}, |
@matiastucci I'm using mongoose and I created all the models inside one folder so I just import any model inside the API |
@iaincollins thanks for looking into this. I added mongo to |
Since I added |
Just to add some search engine optimization to this issue, this error happens when deploying next-auth on Vercel and the solution @iaincollins posted seems to fix it! |
My app is deployed on Vercel and I am getting the same error.
|
I had this issue today twice and will check if I can create an repo to reproduce it. |
I'm getting this seemingly random as well. It starts happening, then nothing is working because of it for a few minutes. Then it disappears again, to come back a few hours later. |
I have added |
- Error: no optional dependency [mongodb] defined in peerOptionalDependencies in any package.json - @see nextauthjs/next-auth#552 (comment)
This is still happening, for example if you switch to using Serverless (AWS) and |
we will see if #1682 helps with this |
This is also happening for me. The weird thing is that I've copied the config from two other very similar applications and they work fine. Mine, not so much. Tried adding peer dependency as mentioned above and no joy. |
In v4, you will explicitly import adapters, and we won't try to import |
my error was |
Describe the bug
I keep getting
Error: no optional dependency [mongodb] defined in peerOptionalDependencies in any package.json
. It's so weird because I see it most of the time but no always. Sometimes I can sign in correctly and sometimes I get redirected to/api/auth/signin?error=Callback#
and see this error in the client:Try signing with a different account
. This is the full error log:To Reproduce
My code is in a private repo but if it's necessary I can try to create a new project and replicate it. My code is pretty standard. Just followed the docs. I only have 1 provider (Google) and I've already tried emptying the 3 collections (
accounts
,users
andsessions
)Documentation 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: