简体   繁体   English

覆盖 package.json 中依赖项的 NPM 依赖项

[英]Overriding NPM dependency of a dependency in package.json

I'm getting the following error when I try to import mongoose with TypeScript当我尝试使用 TypeScript 导入 mongoose 时出现以下错误

node_modules/mongoose/node_modules/mongodb/mongodb.d.ts:3309:5 - error TS2416: Property 'end' in type 'GridFSBucketWriteStream' is not assignable to the same property in base type 'Writable'.

Apparently this was fixed in mongodb 4.3.0, but mongoose uses mongodb 4.2.2显然这已在 mongodb 4.3.0 中修复,但 mongoose 使用 mongodb 4.2.2

How could I force mongoose to use mongodb 4.3.0+?如何强制 mongoose 使用 mongodb 4.3.0+?

I tried adding我尝试添加

  "overrides": {
    "mongoose": {
      "mongodb": "^4.3.0"
    }
  },

to package.json but it didn't fix the issue.到 package.json 但它没有解决问题。

Here's my package.json这是我的 package.json

{
  "name": "reports",
  "version": "1.0.0",
  "type": "module",
  "description": "",
  "main": "index.js",
  "engines": {
    "node": "16.x"
  },
  "jest": {
    "setupFiles": [
      "<rootDir>/jestTestEnv.js"
    ]
  },
  "scripts": {
    "test": "jest --watchAll --setupFiles ./jestTestEnv.js",
    "dev": "tsc && nodemon -r dotenv/config dist/server.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",

  "dependencies": {
    "body-parser": "^1.19.1",
    "cors": "^2.8.5",
    "dotenv": "^10.0.0",
    "express": "^4.17.1",
    "express-jwt": "^6.1.0",
    "express-openid-connect": "^2.5.2",
    "express-validator": "^6.14.0",
    "jwks-rsa": "^2.0.5",
    "mongoose": "^6.1.1"
  },
  "overrides": {
    "mongoose": {
      "mongodb": "^4.3.0"
    }
  },

  "devDependencies": {
    "@types/body-parser": "^1.19.2",
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.13",
    "@types/express-jwt": "^6.0.4",
    "@types/jest": "^27.4.0",
    "@types/node": "^17.0.13",
    "@types/supertest": "^2.0.11",
    "jest": "^27.4.5",
    "supertest": "^6.1.6",
    "typescript": "^4.5.5"
  }
}


Found the solution.找到了解决方案。 There seems to be a bug here with NPM. NPM 似乎有一个错误。 Deleting both node_modules AND package-lock.json and then doing npm install fixes the issue.删除 node_modules 和 package-lock.json 然后执行npm install解决了这个问题。 Deleting node_modules on its own doesn't fix it.自行删除 node_modules 并不能解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM