【问题标题】:Update Angular 6 to 7 - dependency warning and typescript error将 Angular 6 更新到 7 - 依赖警告和打字稿错误
【发布时间】:2018-10-24 08:00:01
【问题描述】:

我使用此链接将我的简单 Angular 前端升级到 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"})

我也有来自 typescript (3.0.1) 的这个错误:

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

谁能建议解决这些依赖警告和打字稿错误的解决方法? 我需要手动更改依赖项吗?如果是,我需要一个示例如何...

【问题讨论】:

  • Angular 实际上有一个你应该使用的官方更新工具。它使更新过程非常简单明了。试试Angular Update
  • 请说出你经历的步骤,否则很难知道。你做了ng update 吗?你的 packages.json 是什么样的?
  • 我从我的链接中执行了以下 ng 命令:ng update @angular/cli @angular/core

标签: angular typescript npm angular7 angular-upgrade


【解决方案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 中没有明确包含这个,因此您可能只需要在运行 ng update 之前执行 npm cache clean -f

如果这仍然不起作用,我建议您删除您的 node_modules 目录,如果您正确更新了您的 package.json(手动或通过ng update)。

【讨论】:

  • 您解决我的依赖问题的解决方案运行良好 :) 我运行了 npm cache clean -f 和后记 ng update --all。无论如何,我仍然有打字稿错误:Error:Initialization error (angular 2 language service). Cannot read property 'CommandTypes' of undefined
  • 好的,然后标记为答案 :) 也更新 Typescript。而这又是一个问题,你得看它是从什么代码抛出来的,如果你不能解决的话,可能是另一个问题在 StackOverflow 上问。
【解决方案2】:

您是否删除了旧的 node_modules 文件夹?如果不是,请删除它,如果它在那里,也删除 package-lock.json。清理 npm 缓存 npm cache clean -f 并尝试安装所有软件包

【讨论】:

    猜你喜欢
    • 2019-11-30
    • 2016-07-21
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    • 2018-10-20
    • 1970-01-01
    相关资源
    最近更新 更多