首页 > 解决方案 > 无法读取 tsconfig.base.json!- Apollo Angular 项目设置

问题描述

ng add apollo-angular

它引发了许多警告:

UPDATE src/app/app.module.ts (541 bytes)
npm WARN notsup Unsupported engine for extract-files@9.0.0: wanted: {"node":"^10.17.0 || ^12.0.0 || >= 13.7.0"} (current: {"node":"10.16.3","npm":"6.12.0"})
npm WARN notsup Not compatible with your version of node/npm: extract-files@9.0.0
npm WARN karma-jasmine-html-reporter@1.5.4 requires a peer of jasmine-core@>=3.5 but none is installed. You must install peer dependencies yourself.
npm WARN @apollo/client@3.1.3 requires a peer of react@^16.8.0 but none is installed. You must install peer dependencies yourself.
npm WARN @apollo/client@3.1.3 requires a peer of subscriptions-transport-ws@^0.9.0 but none is installed. You must install peer dependencies yourself.

因此,在添加了对等依赖项之后,我尝试再添加一次 apollo-angular:

MIA-LT-16354:src SSilwal$ ng add apollo-angular
Skipping installation: Package already installed
? Url to your GraphQL endpoint https://o5x5jzoo7z.sse.codesandbox.io/graphql'
Couldn't read tsconfig.base.json!

环境:

@apollo/client: 3.0.0 apollo-angular:2.0.3 graphql:15.3.0 @angular/core:9.1.7 @angular/cli: 9.1.12 typescript:3.8.3

标签: angularapollo-clientgraphql-js

解决方案


当您的 Angular 项目之前进行版本迁移时,通常会发生此问题,因此tsconfig.base.json缺少或无效。

您可以尝试apollo-angular手动安装,官方文档自行指导

Apollo Angular 官方 安装指南,apollo-angular无需 Angular 原理图

或遵循我在下面提到的本手册更新:


问题作者提出的 Github 问题仅通过更新 Angular 版本来提供修复,请先尝试

在我遇到这个问题的时候,使用下面的命令帮助了一些人,但没有解决我的问题

可以免费试用

ng update @angular/cli --migrate-only --from 9 --to 10
ng update @angular/core --migrate-only --from 9 --to 10

或尝试使用 --force 如果您遇到错误(谨慎使用!!)

tsconfig.base.json这是为解决迁移 Angular 版本引起的问题而提供的解决方案

主要来源:与此问题相关的 Github 问题

请注意,它有一些副作用

在Angulars 官方文档中阅读更多关于如何根据项目的复杂程度正确迁移的信息


我个人使用这个命令来安装所有需要的包,并按照指南添加需要的模块。

ng update apollo-angular --migrate-only --from 1.10.0

或尝试使用 --force 如果您遇到错误(谨慎使用!!)

ng update apollo-angular --migrate-only --from 1.10.0 --force

我希望这有帮助:)

PS在伊朗等一些国家,你可能需要使用代理才能使用 ng add apollo-angular


推荐阅读