Yarn错误:找不到匹配5.31.0版本的@typescript-eslint/type-utils
Docker构建Node应用时Yarn依赖安装报错:找不到@typescript-eslint/type-utils@5.31.0
问题详情
我正在开发基于Docker的Node应用,镜像构建的依赖安装步骤中遇到Yarn错误:找不到匹配5.31.0版本的@typescript-eslint/type-utils。本地通过Nexus安装依赖可正常完成,即使为报错包添加了resolutions配置,仍无法解决该问题。
相关package.json内容如下:
{"name": "my-graphql-service","version": "1.0.0","main": "index.js","repository": "https://github.com/my-graphql-service.git","author": "Itay Tur","license": "MIT","scripts": {"dev:edge2": "NODE_ENV=development nodemon -r dotenv/config src/index.ts dotenv_config_path=config/edge2.env","dev:qa": "NODE_ENV=development nodemon -r dotenv/config src/index.ts dotenv_config_path=config/qa.env","generate:integrations": "node src/generate-integrations-code.js","build": "rimraf build && NODE_ENV=production tsc --project tsconfig.json","start": "NODE_ENV=production node -r dotenv/config build/index.js dotenv_config_path=.env.graph","test": "NODE_ENV=development jest --detectOpenHandles --forceExit","test:watch": "NODE_ENV=development jest --watch --detectOpenHandles --forceExit","format": "prettier --write .","lint": "eslint . --fix","prepare": "husky install"},"resolutions": {"pretty-format": "^26.0.1","jest-diff": "^25.1.0","jest-matcher-utils": "^25.1.0","@typescript-eslint/type-utils": "@5.30.6","@typescript-eslint/utils": "5.30.6"},"dependencies": {"@graphile-contrib/pg-order-by-related": "^1.0.0-beta.6","@graphile-contrib/pg-simplify-inflector": "^6.1.0","@graphile/pg-aggregates": "^0.1.0","@openapitools/openapi-generator-cli": "2.1.22","cors": "^2.8.5","cptls-common-nodejs": "^5.1.5","dataloader": "^2.1.0","dotenv": "^16.0.1","express": "^4.18.1","postgraphile": "^4.12.9","postgraphile-plugin-connection-filter": "^2.3.0","rimraf": "^3.0.2","typescript": "^4.7.4"},"devDependencies": {"@types/express": "^4.17.13","@types/jest": "^28.1.2","@types/supertest": "^2.0.12","@typescript-eslint/eslint-plugin": "^5.29.0","@typescript-eslint/parser": "^5.29.0","eslint": "^8.18.0","husky": "^8.0.0","jest": "^28.1.3","nodemon": "^2.0.16","prettier": "^2.7.1","supertest": "^6.2.3","ts-jest": "^28.0.5","ts-node": "^10.8.1"}}
解决方案
- 修正resolutions配置格式:当前
@typescript-eslint/type-utils的版本号前多了一个@,需改为"@typescript-eslint/type-utils": "5.30.6",和同配置项的@typescript-eslint/utils格式保持一致。 - 强制Yarn遵循resolutions:在Dockerfile的依赖安装命令中添加
--force参数,比如执行yarn install --force,确保Yarn严格按照指定版本拉取依赖,忽略缓存的旧版本信息。 - 确认Docker构建的源地址:本地能正常安装说明Nexus有对应版本,需确保Docker构建时使用的是Nexus镜像源。在Dockerfile中添加
RUN yarn config set registry <你的Nexus私有源地址>,指定依赖拉取源。 - 锁定依赖版本:本地执行
yarn install生成yarn.lock文件,将该文件复制到Docker镜像中(添加COPY yarn.lock .到Dockerfile),然后执行yarn install --frozen-lockfile,强制使用lock文件中已锁定的依赖版本。
内容的提问来源于stack exchange,提问作者Itay Tur
相关产品推荐
相关产品推荐

