Closed
Description
Versions
- NodeJS: 14.15.3
- mongodb-memory-server-*: 6.9.3 and 7.0.0-beta.14
- mongodb: 4.4.2
- system: MacOS, Linux
- Repo https://github.com/MrWook/mongodb-memory-server-circular-dependency
package: mongo-memory-server
What is the Problem?
We updated from node 12 to Node 14 and a warning is thrown with Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency
Code Example
// jest-global.setup.js
const { MongoMemoryServer } = require('mongodb-memory-server')
module.exports = async () => {
const dbName = 'jestDatabaseName'
global.mongodb = await MongoMemoryServer.create({
instance: {
dbName,
port: 56490,
},
})
}
// jest-global.teardown.js
module.exports = async () => {
await global.mongodb.stop(true)
}
Do you know why it happenes?
This seems like a general problem since node 14 for libraries like nodejs/node#32987
The PR from node to throw this warning is nodejs/node#29935
This means there should be a circular dependency in this library
Here is the whole stacktrace with node --trace-warnings node_modules/.bin/jest --no-cache someTest.spec.ts
:
Determining test suites to run...(node:92425) 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> (/someProjectPath/node_modules/mongodb/lib/operations/operation.js:4:38)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Object.newLoader (/someProjectPath/node_modules/pirates/lib/index.js:104:7)
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)
Which means the circular dependency is in mongodb/lib/operations/operation.js:4:38
with const MongoError = require('../core').MongoError;