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

Viewed 70321

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"
  }
}
12 Answers

Same issue here but =>

npm install mongoose@5.11.15 

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.

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

npm i mongoose@5.11.15

and it should be listed in your dependencies like this

"mongoose": "^5.11.15"

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"

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

yarn add mongoose@5.11.15 

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

const MongoError = require('../core').MongoError;

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

Just install mongoose again

npm install mongoose@5.11.15 

This is caused by a deprecation in the current version.

Uninstall current mongoose version and run npm install mongoose@5.11.15.

This should fix the problem.

Related