npm install did not install the correct version in package.json

I am trying to install node_modules for my project, but instead of loading the libraries in package.json, npm install the latest ones. Before I used the command npm to install -g [email protected], did it have any effect? I tried npm install --force, npm install --legacy-peer-deps, and remove node but it has same error My package.

{
"name": "",
"version": "0.1.0",
"private": true,
"homepage": ".",
"dependencies": {
  "@ant-design/icons": "^4.0.0",
  "@ant-design/pro-descriptions": "^1.2.0",
  "@ant-design/pro-form": "^1.15.1",
  "@ant-design/pro-layout": "^6.9.4",
  "@ant-design/pro-table": "^2.17.3",
  "@ant-design/pro-utils": "^1.8.0",
  "@react-hook/resize-observer": "^1.2.0",
  "@testing-library/jest-dom": "^5.11.4",
  "@testing-library/react": "^11.1.0",
  "@testing-library/user-event": "^12.1.10",
  "@types/jest": "^26.0.15",
  "@types/lodash": "^4.14.168",
  "@types/node": "^12.0.0",
  "@types/react": "^16.9.53",
  "@types/react-dom": "^16.9.8",
  "@types/react-router-dom": "^5.1.7",
  "antd": "^4.11.1",
  "antd-img-crop": "^3.14.1",
  "axios": "^0.21.1",
  "cookies": "^0.8.0",
  "env-cmd": "^10.1.0",
  "exceljs": "^4.2.0",
  "file-saver": "^2.0.5",
  "immer": "^8.0.1",
  "js-cookie": "^2.2.1",
  "less": "^4.1.0",
  "less-loader": "^7.3.0",
  "loadable": "^1.0.0",
  "react": "^17.0.1",
  "react-dom": "^17.0.1",
  "react-intl": "^5.10.18",
  "react-redux": "^7.2.2",
  "react-router-dom": "^5.2.0",
  "react-scripts": "4.0.1",
  "read-excel-file": "^5.0.0",
  "redux-injectors": "^1.3.0",
  "redux-saga": "^1.1.3",
  "typed-redux-saga": "1.2.0",
  "typescript": "^4.0.3",
  "web-vitals": "^0.2.4",
  "xlsx": "^0.16.9"
}

Error Screenshot

Thanks so much

Answer

The caret ^ means it can install the most recent compatible version. If you want it to install a specific version, you can remove the ^ in front of the versions.

See package.json docs and semver

The caret will let it install a later version that doesn’t change the first number. For instance your package.json specifies ^4.0.0 for @ant-design/icons, but it installed 4.6.2. Since the 4 didn’t change, that is acceptable.