找不到模块:无法解析 'apollo-client'

Module not found: Can't resolve 'apollo-client'

从 apollo-boost 迁移到@apollo/client 3.x 库时。对于面临此问题的 reactjs-graphql 应用程序。

Failed to compile.
./node_modules/@apollo/react-hooks/lib/react-hooks.esm.js
Module not found: Can't resolve 'apollo-client' in 'C:\geospat\node_modules\@apollo\react-hooks\lib'

供参考使用 apollo-boost-migration and apollo-client-3-migration 文档。

下面是新的package.json

{
  "name": "gui",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@apollo/client": "^3.3.21",
    "graphql": "14.5.8",
    "@material-ui/core": "^4.11.0",
    "leaflet": "1.5.1",
    "luxon": "^1.24.1",
    "moment": "2.24.0",
    "i18next": "17.0.12",
    "i18next-xhr-backend": "3.1.2",
    "@types/jest": "24.0.17",
    "@types/leaflet": "1.5.1",
    "@types/luxon": "^1.24.0",
    "@types/node": "12.7.1",
    "@types/react": "16.9.1",
    "@types/react-dom": "16.8.5",
    "@types/react-leaflet": "2.4.0",
    "@types/react-loader-spinner": "^3.1.0",
    "@types/recharts": "^1.8.16",
    "classnames": "2.2.6",   
    "jest-sonar-reporter": "2.0.0",    
    "node-sass": "4.12.0",
    "normalize.css": "8.0.1",
    "numeral": "2.0.6",
    "ramda": "0.26.1",
    "react": "16.12.0",
    "react-apollo": "3.1.3",
    "react-dom": "16.12.0",
    "react-i18next": "10.12.2",
    "react-idle-timer": "^4.5.2",
    "react-leaflet": "2.4.0",
    "react-loader-spinner": "^3.1.14",
    "react-redux": "7.1.0",
    "react-router-dom": "5.0.1",
    "react-scripts": "3.3.0",
    "redux": "4.0.4",
    "typescript": "3.5.3",
    "use-query-params": "0.4.5"
  }, 
  "devDependencies": {
    "@types/classnames": "2.2.9",
    "@types/debug": "4.1.5",
    "@types/enzyme": "3.10.3",
    "@types/enzyme-adapter-react-16": "1.0.5",
    "@types/enzyme-to-json": "1.5.3",
    "@types/ramda": "0.26.29",
    "@types/react-redux": "7.1.1",
    "@types/react-router-dom": "4.3.5",
    "@types/redux-mock-store": "1.0.1",
    "enzyme": "3.10.0",
    "enzyme-adapter-react-16": "1.14.0",
    "enzyme-to-json": "3.4.0",
    "mock-apollo-client": "1.1.0",
    "react-dates": "21.0.1",
    "react-leaflet-vectorgrid": "2.2.1",
    "recharts": "1.7.1",
    "redux-devtools-extension": "2.13.8",
    "redux-mock-store": "1.5.3",
    "waait": "1.0.5"
  },  
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },  
  "jest": {
    "collectCoverageFrom": [
      "!src/**/*.snap",
      "src/components/**/*.{ts,tsx}",
      "src/configuration/**/*"
    ],
    "transformIgnorePatterns": []
  },
  "jestSonar": {
    "reportPath": "coverage",
    "reportFile": "jest-sonar-report.xml",
    "indent": 4
  }
}

尝试删除旧的 node_modules 目录,然后删除 运行 npm i 命令,但控制台上显示相同的错误。
这里遗漏了什么?

从早期版本或 apollo-boost 迁移到 @apollo/client 3.x 时,需要删除所有其他与 apollo 相关的库,并且它们在代码中的引用(主要是 import 语句)需要替换为 '@apollo/client' .
在上面 package.json 除了“react-apollo”之外,大多数 apollo 包都被删除了。
删除该包后,上述错误消失或被新错误取代。
但它只是将错误的导入语句替换为 '@apollo/client'.

的语句