【问题标题】:Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency警告:在循环依赖中访问模块导出的不存在属性“MongoError”
【发布时间】:2021-05-17 00:28:50
【问题描述】:

我正在使用节点做 API 并使用 Mongoose。当我给yarn dev 启动我的Nodemon 时,Mongo 中出现错误,我不知道如何解决这个问题。有人有什么想法吗? (我使用的是 MongoDB Atlas 数据库)

就在以下错误之后。

yarn run v1.22.5
$ nodemon src/server.js
[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node src/server.js`
(node:752) Warning: Accessing non-existent property 'MongoError' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
(node:752) DeprecationWarning: Listening to events on the Db class has been deprecated and will be removed in the next major version.

我正在使用

  • 节点 v14.15.4
  • npm 6.14.10

我的 package.json

{
  "name": "backend",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev": "nodemon src/server.js"
  },
  "dependencies": {
    "express": "^4.17.1",
    "md5": "^2.3.0",
    "mongoose": "^5.11.16",
    "multer": "^1.4.2",
    "yarn": "^1.22.10"
  },
  "devDependencies": {
    "nodemon": "^2.0.7"
  }
}

【问题讨论】:

标签: node.js mongodb api mongoose nodemon


【解决方案1】:

我认为 Moongose 对版本 ^5.11.16 的依赖发生了变化。 因为我也经历过。 使用以前的版本后,警告消失了。

"mongoose": "^5.11.15"

【讨论】:

    【解决方案2】:

    刚刚发现这个,警告可以忽略它会在接下来的更新中修复

    大家好,

    感谢您的报告!我今天自己遇到了这个问题 在职的。我与 Node 驱动程序团队联系。警告是安全的 忽略并希望在即将发布的版本中消失。

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

    【讨论】:

      【解决方案3】:

      这里有同样的问题,但是 =>

      npm install mongoose@5.11.15 
      

      修正错误信息。

      不要忘记检查 package.json 是否自动将其更改为 5.11.15,如果不是 => 手动输入。

      【讨论】:

        【解决方案4】:

        这是由当前版本中的弃用引起的。 像这样安装以前的5.11.15版本

        npm i mongoose@5.11.15
        

        它应该像这样列在你的依赖项中

        "mongoose": "^5.11.15"
        

        【讨论】:

          【解决方案5】:

          对我来说npm 引起了问题所以你我选择使用yarn,你可以通过运行这个命令来做同样的事情:

          yarn add mongoose@5.11.15 
          

          【讨论】:

            【解决方案6】:

            在node_modules/mongodb/lib/operations/operation.js 中注释掉以下行帮助我解决了问题。

            const MongoError = require('../core').MongoError;
            

            【讨论】:

              【解决方案7】:

              这也发生在我身上。我忘记启动 MongoDB 指南针或您使用的任何 mongo 服务器。此外,不要忘记使用您输入数据的数据库。就我而言:

              1. 使用我的文章(我存储数据的地方)
              2. npm start(因为我在 package.json 中使用了 'npx nodemon –exec npx babel-node src/server.js 的快捷方式)
              3. 尝试检查您是否可以从数据库中找到您的数据。
              4. 然后检查邮递员或您使用的任何东西。
              5. 另外,不要使用 MongoClient.connect('mongodb://localhost:27017',{useNewUrlParser: true} , 我使用而不是使用 MongoClient.connect('mongodb://localhost/my-articles',{useNewUrlParser: true}。

              最主要的是不要忘记启动mongodb服务器

              【讨论】:

                【解决方案8】:

                如果您使用的是 3.6.4 版,则存在一个会产生此错误的错误。 要解决此问题,目前使用 3.6.3 版

                警报链接: https://developer.mongodb.com/community/forums/t/warning-accessing-non-existent-property-mongoerror-of-module-exports-inside-circular-dependency/15411/5

                【讨论】:

                  【解决方案9】:

                  再次安装猫鼬

                  npm install mongoose@5.11.15 
                  

                  【讨论】:

                    【解决方案10】:

                    这是由当前版本中的弃用引起的。

                    卸载当前的 mongoose 版本并运行 npm install mongoose@5.11.15。

                    这应该可以解决问题。

                    【讨论】:

                      【解决方案11】:

                      更新

                      MongoDB NodeJS Driver 3.6.5 已退出。

                      npm i mongodb
                      

                      MongoError 在此版本中已修复。因此,请随时将mongoose 更新为 5.12.0

                      npm i mongoose
                      

                      【讨论】:

                        【解决方案12】:

                        2021

                        这在5.12.1 中(再次)得到修复。将 mongoose 更新到此版本以修复警告。

                        https://github.com/Automattic/mongoose/issues/9900#issuecomment-802166493

                        【讨论】:

                          猜你喜欢
                          • 2021-06-11
                          • 1970-01-01
                          • 2021-03-28
                          • 2021-05-16
                          • 2021-08-21
                          • 2021-02-13
                          • 2021-02-19
                          • 2021-03-01
                          • 2022-06-13
                          相关资源
                          最近更新 更多