mongodb-js / connect-mongodb-session

Lightweight MongoDB-backed session store for Connect and Express
Apache License 2.0
176 stars 35 forks source link

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

Closed jihdeh closed 3 years ago

jihdeh commented 3 years ago

Hello,

I have this kind of weird error using connect-mongo-session:

(node:74445) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency
 at emitCircularRequireWarning (internal/modules/cjs/loader.js:650:11)
    at Object.get (internal/modules/cjs/loader.js:664:5)
    at Object.<anonymous> (/source//node_modules/connect-mongodb-session/node_modules/mongodb/lib/operations/operation.js:4:38)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/source/service/node_modules/connect-mongodb-session/node_modules/mongodb/lib/operations/execute_operation.js:4:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)

Here's the code


const session = require('express-session');
const MongoStore = require('connect-mongodb-session')(session);
app.use(session({
  store: new MongoStore(
     {
        uri: 'mongo:url',
        collection: 'sessions',
        expires: 1000 * 60 * 60 * 24 * 30
      },
      (error) => error && console.log(`mongo error ${error}`)
 ),
});

Package.json

    "express": "^4.17.1",
    "express-session": "^1.17.1",
    "connect-mongo-session": "^2.4.1",
    "mongoose": "^5.11.14",

Thanks for the help.

JoaoOtavioSegantini commented 3 years ago

I'm having the same problem: (node:5739) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency (Use node --trace-warnings ... to show where the warning was created)

Package.json

"connect-mongodb-session": "^2.4.1",
"mongoose": "^5.12.3"

exports.initSession = function() { const store = new MongoDBStore({ uri: keys.DB_CONECT, collection: 'sessions' })

store.on('error', (error) => console.log(error))

return store; }

CRAKZOR commented 3 years ago

same error at Object.<anonymous> (/dev/next-js/.../node_modules/connect-mongodb-session/node_modules/mongodb/lib/operations/operation.js:4:38)

vkarpov15 commented 3 years ago

This should be fixed in 3.0.0, this was a warning printed out with certain older versions of the MongoDB Node driver.