Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency
Asked Answered
C

12

66

I'm doing API with the node and using Mongoose. When I give a yarn dev to start my Nodemon, there is an error in Mongo, I have no idea how to solve this. Would anyone have any ideas? (I'm using the MongoDB Atlas database)

Right after the following error.

yarn run v1.22.5
$ nodemon src/server.js
[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node src/server.js`
(node:752) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:752) DeprecationWarning: Listening to events on the Db class has been deprecated and will be removed in the next major version.

I'm using the

  • Node v14.15.4
  • npm 6.14.10

My package.json

{
  "name": "backend",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev": "nodemon src/server.js"
  },
  "dependencies": {
    "express": "^4.17.1",
    "md5": "^2.3.0",
    "mongoose": "^5.11.16",
    "multer": "^1.4.2",
    "yarn": "^1.22.10"
  },
  "devDependencies": {
    "nodemon": "^2.0.7"
  }
}
Crucifix answered 13/2, 2021 at 13:34 Comment(5)
I believe there are (smaller) Stack Overflow communities for Spanish and Portuguese. If you would rather post here, please use English (you can edit your question now).Oshinski
Does this answer your question? https://mcmap.net/q/297469/-deprecationwarning-listening-to-events-on-the-db-class-has-been-deprecated-and-will-be-removed-in-the-next-major-versionHuysmans
Does this answer your question? Cannot connect to MongoDB because of wrong URIBecame
So i will assume that we should ignore this warning until they fix it in an upcoming version, won't i?Janettjanetta
Here is one related issue list github.com/nodejs/node/issues/32987Irreligion
B
53

Just found this, warning can be ignored it will be fixed in the coming updates

Hi All,

Thanks for reporting! I hit the issue myself today while I was working. I checked in with the Node driver team. The warning is safe to ignore and will hopefully be gone in an upcoming release.

https://developer.mongodb.com/community/forums/t/warning-accessing-non-existent-property-mongoerror-of-module-exports-inside-circular-dependency/15411/6

Benzoin answered 15/2, 2021 at 5:29 Comment(0)
M
37

Same issue here but =>

npm install [email protected] 

fix the error message.

Don't forget to check the package.json if it automatically changed it to 5.11.15, if not => type it manually.

Mediant answered 15/2, 2021 at 8:7 Comment(0)
E
15

This is caused by a deprecation in the current version. Install the previous 5.11.15 version like this

npm i [email protected]

and it should be listed in your dependencies like this

"mongoose": "^5.11.15"
Eisenberg answered 17/2, 2021 at 11:33 Comment(0)
A
15

2021 and beyond

This was fixed (again) in 5.12.1. Update mongoose to this version to fix the warning.

https://github.com/Automattic/mongoose/issues/9900#issuecomment-802166493

Autoradiograph answered 22/3, 2021 at 9:4 Comment(1)
this option is better than reverting to the previous version mentioned in other answersTrask
H
9

UPDATE

MongoDB NodeJS Driver 3.6.5 is out.

npm i mongodb

The MongoError is fixed in this release. So feel free to update mongoose to 5.12.0

npm i mongoose
Huysmans answered 18/3, 2021 at 18:14 Comment(0)
S
8

I think there was a change on the moongose dependency on version ^5.11.16. As I also experienced it. After using previous versions, the warning is gone.

"mongoose": "^5.11.15"
Salman answered 13/2, 2021 at 20:26 Comment(0)
A
2

If you are using version 3.6.4, there is a bug that generates this error. To resolve, for now, use version 3.6.3

Alert link: https://developer.mongodb.com/community/forums/t/warning-accessing-non-existent-property-mongoerror-of-module-exports-inside-circular-dependency/15411/5

Allin answered 15/3, 2021 at 22:51 Comment(0)
A
1

Just install mongoose again

npm install [email protected] 
Ashore answered 18/3, 2021 at 8:19 Comment(0)
V
0

For me npm caused problems so you I chose to use yarn, you can do the same by running this command:

yarn add [email protected] 
Videlicet answered 1/3, 2021 at 7:22 Comment(0)
W
0

Commenting out the following line inside node_modules/mongodb/lib/operations/operation.js helped me solving the problem.

const MongoError = require('../core').MongoError;
Wen answered 8/3, 2021 at 8:45 Comment(0)
C
0

It had happened to me as well. I had forgotten to start the MongoDB compass or any mongo server that you use. Also, do not forget to use your database where you have entered the data. In my case:

  1. use my-articles(where I stored my data)
  2. npm start( as I have used shortcut for 'npx nodemon –exec npx babel-node src/server.js as start in packeage.json)
  3. try to check whether you can find your data or not from the database.
  4. and check in the postman or whatever you use.
  5. Also, instead of using MongoClient.connect('mongodb://localhost:27017',{useNewUrlParser: true} , I used instead of using MongoClient.connect('mongodb://localhost/my-articles',{useNewUrlParser: true}.

The main thing is don't forget to start the mongodb server

Creight answered 10/3, 2021 at 3:28 Comment(0)
T
0

This is caused by a deprecation in the current version.

Uninstall current mongoose version and run npm install [email protected].

This should fix the problem.

Thermy answered 18/3, 2021 at 12:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.