25

I was trying to run mongoDB on node server Full Code here from MongoDB:

My mongo version: 4.4.3

Node version: v15.7.0

I've imported get started code from MongoDB, and here's the code:

const { MongoClient } = require("mongodb");
// Connection URI
const uri =
  "mongodb+srv://sample-hostname:27017/?poolSize=20&writeConcern=majority";
// Create a new MongoClient
const client = new MongoClient(uri);
async function run() {
  try {
    // Connect the client to the server
    await client.connect();
    // Establish and verify connection
    await client.db("admin").command({ ping: 1 });
    console.log("Connected successfully to server");
  } finally {
    // Ensures that the client will close when you finish/error
    await client.close();
  }
}
run().catch(console.dir);

On terminal, when i run "node app.js", it throws me following error:

> (node:79653) Warning: Accessing non-existent property 'MongoError' of
> module exports inside circular dependency (Use `node --trace-warnings
> ...` to show where the warning was created) MongoParseError: URI does
> not have hostname, domain name and tld
>     at parseSrvConnectionString (/home/harmony/Desktop/FruitsProject/node_modules/mongodb/lib/core/uri_parser.js:50:21)
>     at parseConnectionString (/home/harmony/Desktop/FruitsProject/node_modules/mongodb/lib/core/uri_parser.js:594:12)
>     at connect (/home/harmony/Desktop/FruitsProject/node_modules/mongodb/lib/operations/connect.js:284:3)
>     at /home/harmony/Desktop/FruitsProject/node_modules/mongodb/lib/mongo_client.js:225:5
>     at maybePromise (/home/harmony/Desktop/FruitsProject/node_modules/mongodb/lib/utils.js:681:3)
>     at MongoClient.connect (/home/harmony/Desktop/FruitsProject/node_modules/mongodb/lib/mongo_client.js:221:10)
>     at run (/home/harmony/Desktop/FruitsProject/app.js:12:18)
>     at Object.<anonymous> (/home/harmony/Desktop/FruitsProject/app.js:21:1)
bagerard
  • 5,681
  • 3
  • 24
  • 48
Thirumalai vasan
  • 655
  • 2
  • 6
  • 19

6 Answers6

40

The error Accessing non-existent property 'MongoError' of > module exports inside circular dependency is caused by a bug in mongodb 3.6.4

It's already reported here

Back to version 3.6.3 works for me:

npm uninstall mongodb --save

Install version 3.6.3

npm i mongodb@3.6.3
tom
  • 9,550
  • 6
  • 30
  • 49
  • To reference a comment in that thread from a MongoDB employee ".... I checked in with the Node driver team. The warning is safe to ignore and will hopefully be gone in an upcoming release." [Link](https://developer.mongodb.com/community/forums/t/warning-accessing-non-existent-property-mongoerror-of-module-exports-inside-circular-dependency/15411/6) – mikeymurph77 Feb 09 '21 at 21:36
12

For everyone searching about this warning, don't worry, it's just a version bug, and was already reported. Just uninstall the 3.6.4 version and install the version 3.6.3 as answered on @kmgt answer.

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

https://github.com/Automattic/mongoose/issues/9900

Dr4kk0nnys
  • 697
  • 7
  • 13
  • Why wouldn't you just ignore the warning for this mongoError thing? – MiB Mar 10 '21 at 10:58
  • It's never a good idea to ignore warnings, if you research them, and see it's nothing important, then sure, you can ignore. But if something appears on your terminal saying some nonsense you're not sure of, I would suggest to at least search for a little while about it. – Dr4kk0nnys Mar 11 '21 at 11:48
9

I downgraded MongoDB as recommended but that alone didn’t solve the problem.

I had to downgrade mongoose too to get the error removed.

I downgraded to:

MongoDB version 3.6.3 Mongoose version 5.11.15

mcmedal001
  • 136
  • 2
1

You don't have to downgrade your MongoDB, just downgrade your mongoose package to 5.11.15 as in this mention: https://github.com/Automattic/mongoose/issues/9900#issuecomment-778535254 I'm using Mongo v4.4.3 and just downgrade mongoose worked for me.

Duc Tran
  • 21
  • 1
  • 4
0

I have a similar error too, am running on MacOS Catelina:

(node:3265) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency (Use `node --trace-warnings ...` to show where the warning was created) Server started on port 3000

Previously running on:

node: v14.15.4, mongodb: v4.4.3, mongoose: v5.11.18

After downgrading mongoose to v5.11.15, the error is gone.

  1. Uninstall mongoose from terminal
    npm uninstall mongoose

  2. Install mongoose version 5.11.15
    npm i mongoose@5.11.15

spongeabb
  • 21
  • 2
0

[mongo error 1

because of the line which I show in red rectangler over the picture