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

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

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).

  1. yarn why @types/react

gives

  1. => Found "@types/react@18.0.27"
  2. info Has been hoisted to "@types/react"
  3. info Reasons this module exists
  4. - "workspace-aggregator-b9abcbf3-4f80-4556-99aa-e9a250d3385a" depends on it
  5. - Hoisted from "_project_#sdtool#@types#react-relay#@types#react"
  6. - Hoisted from "_project_#sdtool#@types#react-table#@types#react"
  7. - Hoisted from "_project_#sdtool#@vx#vx#@vx#annotation#@types#react"
  8. - Hoisted from "_project_#sdtool#@vx#vx#@vx#axis#@types#react"
  9. - Hoisted from "_project_#sdtool#@vx#vx#@vx#bounds#@types#react"
  10. - Hoisted from "_project_#sdtool#@vx#vx#@vx#clip-path#@types#react"
  11. - Hoisted from "_project_#sdtool#@vx#vx#@vx#drag#@types#react"
  12. - Hoisted from "_project_#sdtool#@vx#vx#@vx#event#@types#react"
  13. - Hoisted from "_project_#sdtool#@vx#vx#@vx#geo#@types#react"
  14. - Hoisted from "_project_#sdtool#@vx#vx#@vx#glyph#@types#react"
  15. - Hoisted from "_project_#sdtool#@vx#vx#@vx#gradient#@types#react"
  16. - Hoisted from "_project_#sdtool#@vx#vx#@vx#grid#@types#react"
  17. - Hoisted from "_project_#sdtool#@vx#vx#@vx#group#@types#react"
  18. - Hoisted from "_project_#sdtool#@vx#vx#@vx#heatmap#@types#react"
  19. - Hoisted from "_project_#sdtool#@vx#vx#@vx#hierarchy#@types#react"
  20. - Hoisted from "_project_#sdtool#@vx#vx#@vx#legend#@types#react"
  21. - Hoisted from "_project_#sdtool#@vx#vx#@vx#marker#@types#react"
  22. - Hoisted from "_project_#sdtool#@vx#vx#@vx#network#@types#react"
  23. - Hoisted from "_project_#sdtool#@vx#vx#@vx#pattern#@types#react"
  24. - Hoisted from "_project_#sdtool#@vx#vx#@vx#responsive#@types#react"
  25. - Hoisted from "_project_#sdtool#@vx#vx#@vx#shape#@types#react"
  26. - Hoisted from "_project_#sdtool#@vx#vx#@vx#text#@types#react"
  27. - Hoisted from "_project_#sdtool#@vx#vx#@vx#tooltip#@types#react"
  28. - Hoisted from "_project_#sdtool#@vx#vx#@vx#voronoi#@types#react"
  29. - Hoisted from "_project_#sdtool#@vx#vx#@vx#zoom#@types#react"
  30. - Hoisted from "_project_#sdtool#@vx#vx#@vx#bounds#@types#react-dom#@types#react"
  31. info Disk size without dependencies: "196KB"
  32. info Disk size with unique dependencies: "1.37MB"
  33. info Disk size with transitive dependencies: "1.37MB"
  34. info Number of shared dependencies: 3
  35. => Found "sdtool#@types/react@17.0.53"
  36. info This module exists because "_project_#sdtool" depends on it.
  37. info Disk size without dependencies: "184KB"
  38. info Disk size with unique dependencies: "1.36MB"
  39. info Disk size with transitive dependencies: "1.36MB"
  40. info Number of shared dependencies: 3
  41. => Found "@types/react-dom#@types/react@17.0.53"
  42. info This module exists because "_project_#sdtool#@types#react-dom" depends on it.
  43. info Disk size without dependencies: "184KB"
  44. info Disk size with unique dependencies: "1.36MB"
  45. info Disk size with transitive dependencies: "1.36MB"
  46. info Number of shared dependencies: 3
  47. Done in 0.69s.

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

  1. dependencies:
  2. "@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

  1. {
  2. "name": "name",
  3. "author": "author",
  4. "private": true,
  5. "version": "0.0.0",
  6. "license": "SEE LICENSE IN LICENSE",
  7. "description": "desc",
  8. "keywords": [
  9. "keyword"
  10. ],
  11. "repository": {
  12. "type": "git",
  13. "url": ""
  14. },
  15. "workspaces": {
  16. "packages": [
  17. "packages/*"
  18. ]
  19. },
  20. "scripts": {
  21. "storybook": "cd packages/sdtool && yarn storybook",
  22. "build": "lerna run build",
  23. "lint": "lerna run lint",
  24. "prettier": "prettier --write \"./packages/**/*.{js,ts,jsx,tsx,json,md,xml}\""
  25. },
  26. "devDependencies": {
  27. "lerna": "^3.22.1",
  28. "prettier": "^2.2.1"
  29. },
  30. "resolutions": {
  31. "babel-loader": "8.1.0",
  32. "react": "17.0.1",
  33. "react-dom": "17.0.1",
  34. "@emotion/styled": "11.0.0",
  35. "@emotion/react": "11.0.0",
  36. "typescript": "^4.0.3"
  37. }
  38. }

packages/pckg_name/package.json

  1. {
  2. "name": "pckg_name",
  3. "version": "1.0.0",
  4. "private": true,
  5. "dependencies": {
  6. "@emotion/react": "^11.1.5",
  7. "@emotion/styled": "^11.10.5",
  8. "@primer/octicons-react": "^12.1.0",
  9. "@testing-library/jest-dom": "^5.11.10",
  10. "@testing-library/react": "^11.2.6",
  11. "@testing-library/user-event": "^13.1.1",
  12. "@types/jest": "^26.0.22",
  13. "@types/node": "^14.14.37",
  14. "@types/react": "^17.0.3",
  15. "@types/react-dom": "^17.0.3",
  16. "@vx/vx": "^0.0.199",
  17. "babel-plugin-relay": "^11.0.1",
  18. "dayjs": "^1.10.4",
  19. "history": "^5.0.0",
  20. "immer": "^9.0.1",
  21. "match-sorter": "^6.3.0",
  22. "react": "^17.0.2",
  23. "react-dom": "^17.0.2",
  24. "react-relay": "11.0.1",
  25. "react-router-dom": "6.0.0-beta.0",
  26. "react-scripts": "4.0.3",
  27. "react-spring": "npm:@react-spring/web@9.0.0",
  28. "react-table": "^7.6.3",
  29. "react-use-gesture": "^9.1.3",
  30. "react-window": "^1.8.6",
  31. "typescript": "^4.2.3",
  32. "web-vitals": "^1.1.1"
  33. },
  34. "scripts": {
  35. "start": "react-scripts --openssl-legacy-provider start",
  36. "build": "yarn relay && react-scripts build",
  37. "test": "react-scripts test",
  38. "lint": "eslint --ext js,ts,tsx src",
  39. "relay": "relay-compiler",
  40. "relay:watch": "relay-compiler --watch",
  41. "storybook": "start-storybook -p 6006 -s public",
  42. "build-storybook": "build-storybook -s public"
  43. },
  44. "eslintConfig": {
  45. "extends": [
  46. "react-app",
  47. "react-app/jest"
  48. ],
  49. "ignorePatterns": [
  50. "*.stories.tsx"
  51. ],
  52. "overrides": [
  53. {
  54. "files": "*.{js,jsx,ts,tsx}",
  55. "rules": {
  56. "no-console": [
  57. 2,
  58. {
  59. "allow": [
  60. "warn",
  61. "error"
  62. ]
  63. }
  64. ]
  65. }
  66. }
  67. ]
  68. },
  69. "browserslist": {
  70. "production": [
  71. ">0.2%",
  72. "not dead",
  73. "not op_mini all"
  74. ],
  75. "development": [
  76. "last 1 chrome version",
  77. "last 1 firefox version",
  78. "last 1 safari version"
  79. ]
  80. },
  81. "devDependencies": {
  82. "@storybook/addon-actions": "^6.2.3",
  83. "@storybook/addon-essentials": "^6.2.3",
  84. "@storybook/addon-links": "^6.2.3",
  85. "@storybook/node-logger": "^6.2.3",
  86. "@storybook/preset-create-react-app": "^3.1.7",
  87. "@storybook/react": "^6.2.3",
  88. "@types/react-relay": "^11.0.1",
  89. "@types/react-table": "^7.0.29",
  90. "@types/relay-runtime": "^11.0.0",
  91. "graphql": "^15.5.0",
  92. "relay-compiler": "^11.0.1",
  93. "relay-compiler-language-typescript": "^13.0.9",
  94. "relay-config": "^11.0.1",
  95. "relay-test-utils": "^11.0.1"
  96. },
  97. "resolutions": {
  98. "@types/react": "^17.0.3"
  99. }
  100. }

答案1

得分: 1

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

  1. "resolutions": {
  2. "@types/react": "^17.0.3"
  3. }
英文:

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

  1. "resolutions": {
  2. "@types/react": "^17.0.3"
  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:

确定