将Angular 6更新为7-依赖项警告和打字稿错误

时间:2018-10-24 08:00:02

标签: angular typescript npm angular7 angular-upgrade

我使用此链接将我的简单角度前端升级到Angular 7:

Update to Angular 7

在更新时,我收到关于package.json和polyfills.ts文件的一些警告:

UPDATE package.json (1313 bytes)
npm WARN @ngtools/webpack@6.1.5 requires a peer of typescript@~2.4.0 || ~2.5.0 || ~2.6.0 || ~2.7.0 || ~2.8.0 || ~2.9.0 but none is installed. You must install peer dependencies yourself.
npm WARN codelyzer@4.2.1 requires a peer of @angular/compiler@>=2.3.1 <7.0.0 || >6.0.0-beta <7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN codelyzer@4.2.1 requires a peer of @angular/core@>=2.3.1 <7.0.0 || >6.0.0-beta <7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN codelyzer@4.2.1 requires a peer of @angular/platform-browser-dynamic@>=2.3.1 <7.0.0 || >6.0.0-beta <7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN codelyzer@4.2.1 requires a peer of @angular/platform-browser@>=2.3.1 <7.0.0 || >6.0.0-beta <7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN codelyzer@4.2.1 requires a peer of @angular/common@>=2.3.1 <7.0.0 || >6.0.0-beta <7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

added 69 packages, removed 4 packages, updated 16 packages and moved 2 packages in 43.395s
UPDATE package.json (1315 bytes)
UPDATE src/polyfills.ts (3165 bytes)
npm WARN codelyzer@4.2.1 requires a peer of @angular/compiler@>=2.3.1 <7.0.0 || >6.0.0-beta <7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN codelyzer@4.2.1 requires a peer of @angular/core@>=2.3.1 <7.0.0 || >6.0.0-beta <7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN codelyzer@4.2.1 requires a peer of @angular/platform-browser-dynamic@>=2.3.1 <7.0.0 || >6.0.0-beta <7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN codelyzer@4.2.1 requires a peer of @angular/platform-browser@>=2.3.1 <7.0.0 || >6.0.0-beta <7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN codelyzer@4.2.1 requires a peer of @angular/common@>=2.3.1 <7.0.0 || >6.0.0-beta <7.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

我也有打字稿(3.0.1)中的错误:

Error:Initialization error (angular 2 language service). Cannot read property 'CommandTypes' of undefined

有人可以建议解决方法,以解决这些依赖关系警告和打字稿错误吗? 我需要手动更改依赖项吗?如果是的话,我需要一个示例来说明...

2 个答案:

答案 0 :(得分:1)

问题是您没有这两个软件包的最新版本。

  1. 您需要将软件包Codelyzer更新到最新版本。 ng update --all应该可以这样做,否则您也可以手动编辑package.json

您会看到here已使该软件包的最新版本(4.5.0)与Angular 7兼容,因此您需要使用它而不是4.2.1版本。

  1. 与您的@ngtools/webpack相同,您需要使用最新版本(请参见here,它是7.0.2)。可能您的packages.json中没有明确显示此代码,因此您可能只需要在运行npm cache clean -f之前执行ng update

如果仍然无法执行此操作,建议您删除node_modules目录,这将强制npm install从存储库中的最新版本重建所有文件,前提是您正确更新了{{1 }}(手动或通过package.json)。

答案 1 :(得分:0)

您是否删除了旧的import { Injectable } from '@angular/core'; import { HttpClient} from '@angular/common/http'; interface IuserData{ userId: number; } @Injectable({ providedIn: 'root' }) export class HttpService { constructor(private http: HttpClient) { } getUserId(){ return this.http.get<IuserData>("https://jsonplaceholder.typicode.com/todos/1").subscribe(data => { console.log('User ID: ' + data.userId) }) } } 文件夹?如果没有,请删除它,如果存在,请同时删除package-lock.json。清理npm缓存node_modules并尝试安装所有软件包