21

I am just trying to create an API and connect to it inside my app.js file but every time I run app.js I am getting this deprecation warning. I have checked all of the deprecation warnings in mongoose and MongoDB but I cannnot find any that match mine. The warning that I am getting is,

(node:16864) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency

(Use node --trace-warnings ... to show where the warning was created)

(node:16864) DeprecationWarning: Listening to events on the Db class has been deprecated and will be removed in the next major version.

Why am I getting this deprecation warning and how can I remove it?

Ayush
  • 303
  • 2
  • 12
  • 5
    Does [this](https://stackoverflow.com/questions/66049860/cannot-connect-to-mongodb-because-of-wrong-uri/66102270#66102270) answer your question? – J.F. Feb 12 '21 at 23:00
  • 1
    About the first warning: The Mongo driver team [is aware](https://developer.mongodb.com/community/forums/t/warning-accessing-non-existent-property-mongoerror-of-module-exports-inside-circular-dependency/15411/6?u=haniel_baez) of, and the warning is safe to ignore and will hopefully be gone in an upcoming release. – Haniel Baez Feb 12 '21 at 23:10
  • @J.F. it still does not resolve the second deprecation warning that i am getting –  Ayush Feb 13 '21 at 08:01

3 Answers3

12

I guess this warning occurs with mongoose 5.11.16 version. If you want to avoid seeing them until the bug gets fixed, instead you can go for mongoose version 5.11.15. Uninstall mongoose 5.11.16 and install npm install mongoose@5.11.15

Walker
  • 644
  • 1
  • 6
  • 3
  • this one worked. thanks but i also want to know why this deprecation warning was occuring just like for the first warning was just a bug. is this one also a bug? –  Ayush Feb 14 '21 at 10:39
  • @Ayush Check this answer https://stackoverflow.com/a/66194937/7229801 and the conversation at the forum https://developer.mongodb.com/community/forums/t/warning-accessing-non-existent-property-mongoerror-of-module-exports-inside-circular-dependency/15411 – Avani Khabiya Feb 17 '21 at 07:05
  • There also is a separate question posted on Mongodb forum for this warning. Please check https://developer.mongodb.com/community/forums/t/node-44612-deprecationwarning-listening-to-events-on-the-db-class-has-been-deprecated-and-will-be-removed-in-the-next-major-version/15849 as mentioned in the answer https://stackoverflow.com/a/66272570/7229801 – Avani Khabiya Feb 23 '21 at 06:34
-2

Ya Its correct mongoose version problem. so please 5.11.16 version change to 5.11.15 version.

npm install --save mongoose@5.11.15

Dhilip
  • 1
  • 1
-2

The problem is with the new version which is above 5.11.15

Check your version by running:

npm list | grep "mongoose"

Then move to version 5.11.15 by running:

npm install --save mongoose@5.11.15

It worked that way.

mediocrevegetable1
  • 4,086
  • 1
  • 11
  • 33