Skip to content

Node 14 circular dependency #433

Closed
BetaHuhn/qrgen
#161
@MrWook

Description

@MrWook

Versions

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions