覆盖 package.json 中依赖项的 NPM 依赖项
Overriding NPM dependency of a dependency in package.json
当我尝试使用 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'.
显然这已在 mongodb 4.3.0 中修复,但 mongoose 使用 mongodb 4.2.2
如何强制猫鼬使用 mongodb 4.3.0+?
我试过添加
"overrides": {
"mongoose": {
"mongodb": "^4.3.0"
}
},
到 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"
}
}
找到解决方案。 NPM 似乎有一个错误。删除 node_modules 和 package-lock.json 然后执行 npm install
可以解决问题。单独删除 node_modules 并不能解决问题。
当我尝试使用 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'.
显然这已在 mongodb 4.3.0 中修复,但 mongoose 使用 mongodb 4.2.2
如何强制猫鼬使用 mongodb 4.3.0+?
我试过添加
"overrides": {
"mongoose": {
"mongodb": "^4.3.0"
}
},
到 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"
}
}
找到解决方案。 NPM 似乎有一个错误。删除 node_modules 和 package-lock.json 然后执行 npm install
可以解决问题。单独删除 node_modules 并不能解决问题。