微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

找不到模块:无法解析“阿波罗客户端”

如何解决找不到模块:无法解析“阿波罗客户端”

从 apollo-boost 迁移到 @apollo/client 3.x lib。 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-migrationapollo-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' 的导入语句替换了错误的导入语句。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。