【问题标题】:Install missing dependencies in angular 10在 Angular 10 中安装缺少的依赖项
【发布时间】:2020-11-18 21:12:57
【问题描述】:

我在我的 angular 10 中使用 apollo,运行 ng serve 后我遇到了这个问题

目标入口点“apollo-angular”中的错误已丢失 依赖:

  • @angular/core
  • 阿波罗客户端
  • rxjs
  • rxjs/运营商
  • 阿波罗链接

是否有一个命令可以在我的项目中安装所有这些缺少的依赖项......即使我认为我已经安装了所有这些......奇怪的是我有这些错误。 谁能给我一些智慧,提前谢谢你

【问题讨论】:

  • 看起来你没有在你的 ngModule 中导入或声明为提供者 ApolloModule。您是否按照文档的所有步骤进行操作? apollographql.com/docs/angular/basics/setup
  • @Meadow 我确实运行了ng add apollo-angular ...你需要设置的是你的GraphQL服务器的URL,所以打开src/app/graphql.module.ts....我找不到这个文件
  • 移除 apollo-angular 并重新添加。此处显示控制台中显示的 ng add 命令的完整日志。你应该有这个日志: CREATE src/app/graphql.module.ts || PS:另外,你的 Angular 版本是什么?
  • @Meadow 我卸载了所有 npm 包,重新安装了....创建了一个新项目,给了我这个:::ng add apollo-angular 跳过安装:包已安装 发生未处理的异常:找不到模块 '@angular-devkit/schematics' 需要堆栈:lar\schematics\install\index.js \@angular-devkit\schematics\tools\export-ref.js \@angular-devkit\schematics\tools\index.js \ @angular\cli\utilities\json-schema.js \@angular\cli\models\command-runner.js \@angular\cli\lib\cli\index.js _modules\@angular\cli\lib\init.js _modules\@angular\cli\bin\
  • 你的@angular/cli 版本是否大于9?尝试删除 nodes_modules 文件夹并删除 package-lock.json 文件,然后执行:npm i

标签: angular apollo apollo-client apollo-angular


【解决方案1】:

我对“@apollo/client/core”也有同样的问题

ERROR in The target entry-point "apollo-angular" has missing dependencies:

@apollo/client/core

从 apollo.d.ts 中的“@apollo/client/core”导入无法正常工作。将 apollo-angular 降级到 1.10.0 解决了这个问题。文档说它支持 Angular 10。此版本中 apollo.d.ts 中的导入如下所示:

import { ApolloClient, QueryOptions, MutationOptions, ApolloQueryResult, SubscriptionOptions, ApolloClientOptions } from 'apollo-client';

这就是我的 package.json 中的依赖项的样子:

"apollo-angular": "^1.10.0",
"apollo-angular-link-http": "^1.11.0",
"apollo-cache-inmemory": "^1.6.6",
"apollo-client": "^2.6.10",
"apollo-link": "^1.2.14",
"graphql": "^15.1.0",
"graphql-tag": "^2.10.4",

【讨论】:

    【解决方案2】:

    来自apollo-angular#installation 文档:

    如果您使用的是 Apollo-Client v3,请务必使用 apollo-angular@v2

    如果您使用的是 Apollo-Client v2,请确保使用 apollo-angular@v1(对于 Angular 10 支持,请确保使用 v1.10.0)

    我正在使用角度 v11.0.3。将apollo-angular 降级为v1.10.0 后。编译成功。

    删除apollo-angular v2。

    npm rm apollo-angular -S
    

    安装apollo-angular@1.10.0:

    npm i apollo-angular@1.10.0 -S
    

    package.json:

     "dependencies": {
        "@angular/animations": "~11.0.3",
        "@angular/common": "~11.0.3",
        "@angular/compiler": "~11.0.3",
        "@angular/core": "~11.0.3",
        "@angular/forms": "~11.0.3",
        "@angular/platform-browser": "~11.0.3",
        "@angular/platform-browser-dynamic": "~11.0.3",
        "@angular/router": "~11.0.3",
        "apollo-angular": "^1.10.0",
        "apollo-angular-link-http": "^1.11.0",
        "apollo-cache-inmemory": "^1.6.6",
        "apollo-client": "^2.6.10",
        "apollo-link": "^1.2.14",
        "apollo-link-error": "^1.1.13",
        "detect-browser": "^5.2.0",
        "graphql": "^15.4.0",
        "graphql-codegen-add": "^0.18.2",
        "graphql-tag": "^2.11.0",
        "rxjs": "~6.6.0",
        "tslib": "^2.0.0",
        "zone.js": "~0.10.2"
      },
    

    【讨论】:

      【解决方案3】:

      我也遇到了同样的问题。 Angular 10 不能很好地与 Apollo 配合使用。恢复到以前的 Angular 版本应该可以修复它。

      您可以将 package.json 中的 Angular 版本更改为类似

          "dependencies": {
              "@angular/animations": "~9.1.7",
              "@angular/common": "~9.1.7",
              "@angular/compiler": "~9.1.7",
              "@angular/core": "~9.1.7",
              "@angular/forms": "~9.1.7",
              "@angular/platform-browser": "~9.1.7",
              "@angular/platform-browser-dynamic": "~9.1.7",
              "@angular/router": "~9.1.7"
      

      或者任何你喜欢的,只要它在 Angular 10 之前。

      删除package-lock.json后,删除node_module并执行

      npm i
      

      【讨论】:

        【解决方案4】:

        结帐:https://apollo-angular.com/docs/get-started

        npm install apollo-angular @apollo/client graphql
        

        【讨论】:

          猜你喜欢
          • 2017-07-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2022-11-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多