Rooz
Rooz

Reputation: 824

Overriding NPM dependency of a dependency in package.json not working if the dependency was already installed

I'm getting the following error when I try to import mongoose with TypeScript

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

How could I force mongoose to use mongodb 4.3.0+ ?

I tried adding

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

to package.json but it didn't fix the issue.

Here's my 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"
  }
}


Upvotes: 10

Views: 30480

Answers (2)

Alex K
Alex K

Reputation: 15888

I am still encountering this bug on npm 10.2.5.

My workaround was to go delete the entry for the offending package from package-lock.json by hand before running npm install.

I do not recommend deleting the entire package-lock.json. Deleting node_modules should also not be necessary.

Upvotes: 3

Rooz
Rooz

Reputation: 824

Found the solution. There seems to be a bug here with NPM. Deleting both node_modules AND package-lock.json and then doing npm install fixes the issue. Deleting node_modules on its own doesn't fix it.

Upvotes: 23

Related Questions