Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node 14 circular dependency #433

Closed
MrWook opened this issue Feb 5, 2021 · 9 comments · Fixed by BetaHuhn/qrgen#161
Closed

Node 14 circular dependency #433

MrWook opened this issue Feb 5, 2021 · 9 comments · Fixed by BetaHuhn/qrgen#161
Labels
bug released on @beta released Pull Request released | Issue is fixed

Comments

@MrWook
Copy link

MrWook commented Feb 5, 2021

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;

@MrWook MrWook added the bug label Feb 5, 2021
@MrWook
Copy link
Author

MrWook commented Feb 5, 2021

I just saw this isn't even re right repo i'm sorry. Its the main mongodb repo

@MrWook MrWook closed this as completed Feb 5, 2021
@MrWook
Copy link
Author

MrWook commented Feb 5, 2021

Actually it is a combination from the global jest setup and mongodb-memory-server. If you use mongodb directly in the global jest setup to connect to a server everything works fine. If you create a server with this library it will throw the warning

I created a reproduction repo https://github.com/MrWook/mongodb-memory-server-circular-dependency

@MrWook MrWook reopened this Feb 5, 2021
@hasezoey
Copy link
Collaborator

hasezoey commented Feb 5, 2021

confirmed also happening when upgrading typegoose to @beta of this package

but i still have no clue what is causing this, but it dosnt seem to affect anything (yet?)

PS: for typegoose it is only happening when upgrading to 7.0 (beta), but not in an 6.x release, @MrWook did it really also happen in 6.9.3 for you?

@hasezoey
Copy link
Collaborator

hasezoey commented Feb 21, 2021

update: found an mongoose issue about it: Automattic/mongoose#9900
(PR in mongodb driver: mongodb/node-mongodb-native#2734)

TL;DR: its an mongodb driver issue, the driver needs to be updated to fix this error

@MrWook
Copy link
Author

MrWook commented Feb 26, 2021

I get it in 6.9.3 but like i said only when i use it in the jest global setup. It don't break anything on my end either it is just pretty scary to see :D

Good thing it is something so simple, i guess it should be in the next mongodb release then

@hasezoey
Copy link
Collaborator

I get it in 6.9.3 but like i said only when i use it in the jest global setup. It don't break anything on my end either it is just pretty scary to see :D

cant fix for now, because the version where it got fixed in the mongodb driver didnt release yet (and it dosnt seem like they will release it in an minor/patch version)

@hasezoey
Copy link
Collaborator

hasezoey commented Mar 8, 2021

237177b should fix this for 6.x

@github-actions
Copy link

github-actions bot commented Mar 8, 2021

@github-actions
Copy link

🎉 This issue has been resolved in version 7.0.0-beta.48 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment