防止Yarn安装更新的软件包版本以避免冲突。

huangapple go评论61阅读模式
英文:

Prevent yarn from installing a newer package version to avoid conflicts

问题

以下是您要翻译的部分:

My project has a conflict on @types/react because yarn keeps installing the newer version instead of the old one I need (^17.0.3).

yarn why @types/react

gives

=> Found "@types/react@18.0.27"
info Has been hoisted to "@types/react"
info Reasons this module exists

  • "workspace-aggregator-b9abcbf3-4f80-4556-99aa-e9a250d3385a" depends on it
  • Hoisted from "project#sdtool#@types#react-relay#@types#react"
  • Hoisted from "project#sdtool#@types#react-table#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#annotation#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#axis#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#bounds#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#clip-path#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#drag#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#event#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#geo#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#glyph#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#gradient#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#grid#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#group#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#heatmap#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#hierarchy#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#legend#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#marker#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#network#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#pattern#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#responsive#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#shape#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#text#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#tooltip#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#voronoi#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#zoom#@types#react"
  • Hoisted from "project#sdtool#@vx#vx#@vx#bounds#@types#react-dom#@types#react"
    info Disk size without dependencies: "196KB"
    info Disk size with unique dependencies: "1.37MB"
    info Disk size with transitive dependencies: "1.37MB"
    info Number of shared dependencies: 3
    => Found "sdtool#@types/react@17.0.53"
    info This module exists because "project#sdtool" depends on it.
    info Disk size without dependencies: "184KB"
    info Disk size with unique dependencies: "1.36MB"
    info Disk size with transitive dependencies: "1.36MB"
    info Number of shared dependencies: 3
    => Found "@types/react-dom#@types/react@17.0.53"
    info This module exists because "project#sdtool#@types#react-dom" depends on it.
    info Disk size without dependencies: "184KB"
    info Disk size with unique dependencies: "1.36MB"
    info Disk size with transitive dependencies: "1.36MB"
    info Number of shared dependencies: 3
    Done in 0.69s.

In fact I can see from the yarn.lock file that the packages you see above have the following dependency:

dependencies:
"@types/react" "*"

So how I can lock yarn on sticking to the version 17 of @types/react?

UPDATE: these are my packages.json

package.json

{
"name": "name",
"author": "author",
"private": true,
"version": "0.0.0",
"license": "SEE LICENSE IN LICENSE",
"description": "desc",
"keywords": [
"keyword"
],
"repository": {
"type": "git",
"url": ""
},
"workspaces": {
"packages": [
"packages/"
]
},
"scripts": {
"storybook": "cd packages/sdtool && yarn storybook",
"build": "lerna run build",
"lint": "lerna run lint",
"prettier": "prettier --write "./packages/**/
.{js,ts,jsx,tsx,json,md,xml}""
},
"devDependencies": {
"lerna": "^3.22.1",
"prettier": "^2.2.1"
},
"resolutions": {
"babel-loader": "8.1.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"@emotion/styled": "11.0.0",
"@emotion/react": "11.0.0",
"typescript": "^4.0.3"
}
}

packages/pckg_name/package.json

{
"name": "pckg_name",
"version": "1.0.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.1.5",
"@emotion/styled": "^11.10.5",
"@primer/octicons-react": "^12.1.0",
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^13.1.1",
"@types/jest": "^26.0.22",
"@types/node": "^14.14.37",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.3",
"@vx/vx": "^0.0.199",
"babel-plugin-relay": "^11.0.1",
"dayjs": "^1.10.4",
"history": "^5.0.0",
"immer": "^9.0.1",
"match-sorter": "^6.3.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-relay": "11.0.1",
"react-router-dom": "6.0.0-beta.0",
"react-scripts": "4.0.3",
"react-spring": "npm:@react

英文:

My project has a conflict on @types/react because yarn keeps installing the newer version instead of the old one I need (^17.0.3).

yarn why @types/react

gives

=> Found "@types/react@18.0.27"
info Has been hoisted to "@types/react"
info Reasons this module exists
   - "workspace-aggregator-b9abcbf3-4f80-4556-99aa-e9a250d3385a" depends on it
   - Hoisted from "_project_#sdtool#@types#react-relay#@types#react"
   - Hoisted from "_project_#sdtool#@types#react-table#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#annotation#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#axis#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#bounds#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#clip-path#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#drag#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#event#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#geo#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#glyph#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#gradient#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#grid#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#group#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#heatmap#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#hierarchy#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#legend#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#marker#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#network#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#pattern#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#responsive#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#shape#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#text#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#tooltip#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#voronoi#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#zoom#@types#react"
   - Hoisted from "_project_#sdtool#@vx#vx#@vx#bounds#@types#react-dom#@types#react"
info Disk size without dependencies: "196KB"
info Disk size with unique dependencies: "1.37MB"
info Disk size with transitive dependencies: "1.37MB"
info Number of shared dependencies: 3
=> Found "sdtool#@types/react@17.0.53"
info This module exists because "_project_#sdtool" depends on it.
info Disk size without dependencies: "184KB"
info Disk size with unique dependencies: "1.36MB"
info Disk size with transitive dependencies: "1.36MB"
info Number of shared dependencies: 3
=> Found "@types/react-dom#@types/react@17.0.53"
info This module exists because "_project_#sdtool#@types#react-dom" depends on it.
info Disk size without dependencies: "184KB"
info Disk size with unique dependencies: "1.36MB"
info Disk size with transitive dependencies: "1.36MB"
info Number of shared dependencies: 3
Done in 0.69s.

In fact I can see from the yarn.lock file that the packages you see above have the following dependency:

  dependencies:
    "@types/react" "*"

So how I can lock yarn on sticking to the version 17 of @types/react?

UPDATE: these are my packages.json

package.json

{
  "name": "name",
  "author": "author",
  "private": true,
  "version": "0.0.0",
  "license": "SEE LICENSE IN LICENSE",
  "description": "desc",
  "keywords": [
    "keyword"
  ],
  "repository": {
    "type": "git",
    "url": ""
  },
  "workspaces": {
    "packages": [
      "packages/*"
    ]
  },
  "scripts": {
    "storybook": "cd packages/sdtool && yarn storybook",
    "build": "lerna run build",
    "lint": "lerna run lint",
    "prettier": "prettier --write \"./packages/**/*.{js,ts,jsx,tsx,json,md,xml}\""
  },
  "devDependencies": {
    "lerna": "^3.22.1",
    "prettier": "^2.2.1"
  },
  "resolutions": {
    "babel-loader": "8.1.0",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "@emotion/styled": "11.0.0",
    "@emotion/react": "11.0.0",
    "typescript": "^4.0.3"
  }
}

packages/pckg_name/package.json

{
  "name": "pckg_name",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.1.5",
    "@emotion/styled": "^11.10.5",
    "@primer/octicons-react": "^12.1.0",
    "@testing-library/jest-dom": "^5.11.10",
    "@testing-library/react": "^11.2.6",
    "@testing-library/user-event": "^13.1.1",
    "@types/jest": "^26.0.22",
    "@types/node": "^14.14.37",
    "@types/react": "^17.0.3",
    "@types/react-dom": "^17.0.3",
    "@vx/vx": "^0.0.199",
    "babel-plugin-relay": "^11.0.1",
    "dayjs": "^1.10.4",
    "history": "^5.0.0",
    "immer": "^9.0.1",
    "match-sorter": "^6.3.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-relay": "11.0.1",
    "react-router-dom": "6.0.0-beta.0",
    "react-scripts": "4.0.3",
    "react-spring": "npm:@react-spring/web@9.0.0",
    "react-table": "^7.6.3",
    "react-use-gesture": "^9.1.3",
    "react-window": "^1.8.6",
    "typescript": "^4.2.3",
    "web-vitals": "^1.1.1"
  },
  "scripts": {
    "start": "react-scripts --openssl-legacy-provider start",
    "build": "yarn relay && react-scripts build",
    "test": "react-scripts test",
    "lint": "eslint --ext js,ts,tsx src",
    "relay": "relay-compiler",
    "relay:watch": "relay-compiler --watch",
    "storybook": "start-storybook -p 6006 -s public",
    "build-storybook": "build-storybook -s public"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ],
    "ignorePatterns": [
      "*.stories.tsx"
    ],
    "overrides": [
      {
        "files": "*.{js,jsx,ts,tsx}",
        "rules": {
          "no-console": [
            2,
            {
              "allow": [
                "warn",
                "error"
              ]
            }
          ]
        }
      }
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@storybook/addon-actions": "^6.2.3",
    "@storybook/addon-essentials": "^6.2.3",
    "@storybook/addon-links": "^6.2.3",
    "@storybook/node-logger": "^6.2.3",
    "@storybook/preset-create-react-app": "^3.1.7",
    "@storybook/react": "^6.2.3",
    "@types/react-relay": "^11.0.1",
    "@types/react-table": "^7.0.29",
    "@types/relay-runtime": "^11.0.0",
    "graphql": "^15.5.0",
    "relay-compiler": "^11.0.1",
    "relay-compiler-language-typescript": "^13.0.9",
    "relay-config": "^11.0.1",
    "relay-test-utils": "^11.0.1"
  },
  "resolutions": {
    "@types/react": "^17.0.3"
  }
}

答案1

得分: 1

你可以通过在你的package.json中添加解析来强制指定依赖项的版本:

"resolutions": {
    "@types/react": "^17.0.3"
}
英文:

You may force a version of dependency by adding resolutions to your package.json:

"resolutions": {
    "@types/react": "^17.0.3"
}

huangapple
  • 本文由 发表于 2023年2月8日 21:57:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75386833.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定