VS 2019 在 ng cli 更新到版本 10 后没有智能感知和验证

VS 2019 no intellisense and validation after ng cli update to version 10

我已经将我的 .NET 核心 3.1+Angular 9.1 更新到 Angular 10.0.2, 我使用的步骤:

  1. 将 Vs TypeScript 更新为 3.9.5
  2. 运行 ng update @angular/core @angular/cli

之后 VS 2019 v 16.6.3 显示没有智能感知和验证,项目 运行s 没有问题。 如果我在 VS Code 中打开项目,一切正常

我发现问题就在我 运行 ng update @angular/cli

将项目恢复到 9.1 一切正常

谢谢

我在将项目升级到 Angular 10 后遇到了同样的问题。这似乎是最新版本 Visual Studio 2019 未处理对 tsconfig.json 的更改的问题文件和简介 tsconfig.base.json.

作为在 VS 2019 中解决此问题之前的解决方法,我将 tsconfig.base.json 的内容复制到 tsconfig.json 并注释掉升级后的配置。

我现在有一个看起来像这样的文件,并且恢复了旧功能

/*
  This is a "Solution Style" tsconfig.json file, and is used by editors and TypeScript’s language server to improve development experience.
  It is not intended to be used to perform a compilation.

  To learn more about this file see: https://angular.io/config/solution-tsconfig.

  removed this as causes vs 2019 to fail - the config details are copied from base so when this is sort we can revert

  "files": [],
  "references": [
    {
      "path": "./src/tsconfig.app.json"
    },
    {
      "path": "./src/tsconfig.spec.json"
    },
    {
      "path": "./src/tsconfig.server.json"
    },
    {
      "path": "./e2e/tsconfig.e2e.json"
    }
  ]

*/
{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "module": "esnext",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "enableIvy": true
  }
}

我从 Angular 9 迁移到 Angular 10 后遇到了完全相同的问题。

我发现以下对我有用:

TL;DR

在所有 'project' 级别的 tsconfig 文件中(tsconfig.app.json、tsconfig.spec.json、tsconfig.e2e.json)只需更改 'extends' 属性来自:

{
   "extends": "../tsconfig.json"
   ...
}

以下内容:

{
   "extends": "../tsconfig.base.json"
   ...
}

完整版

在 运行 ng update 之前我有以下结构:

ClientApp
|_ tsconfig.json
|_ src
   |_ tsconfig.app.json
   |_ tsconfig.spec.json
|_ e2e
   |_ tsconfig.e2e.json

在 运行 ng update 之后我有以下结构:

ClientApp
|_ tsconfig.json
|_ tsconfig.base.json
|_ src
   |_ tsconfig.app.json
   |_ tsconfig.spec.json
|_ e2e
   |_ tsconfig.e2e.json

阅读 Angular 迁移说明后,我注意到我的 tsconfig.jsontsconfig.base.json 版本是相同的。这仍然有效,但它与 Angular 在注释中描述的不符。所以我决定改变我的`tsconfig.json。手动到以下内容:

{
    "files": [],
    "references": [
        {
            "path": "./src/tsconfig.app.json"
        },
        {
            "path": "./src/tsconfig.spec.json"
        },
        {
            "path": "./e2e/tsconfig.e2e.json"
        }
    ]
}

和其他人一样,它破坏了我的应用程序。

所以我查看了 'project' 级别的 tsconfig 文件并注意到 'extends' 属性 仍然指向 tsconfig.json 而不是 tsconfig.base.json .将我的 'project' 级别的 tsconfig 文件更新为指向 tsconfig.base.json 文件后,一切正常。

快乐的日子!

:-)

我猜测 ng update 应该“自动”查找并更新所有 'project' 级别的 tsconfig 文件,但看起来它没有。不过,修复方法相当简单。


更新

尽管更改 extends 属性 确实解决了我的编译问题。当我第二天关闭并重新打开 Visual Studio 时,IntelliSense 开始失败。

只有使 tsconfig.jsontsconfig.base.json 相同,才能使编译和 IntelliSense 正常工作。

更新

这似乎适用于 visual studio 16.7.1


我在更新到 angular 10 时遇到了同样的问题。它似乎是 known issue 并且修复程序已经在预览中可用。

在修复程序可用于 public 之前,tsconfig.json 中的更改为我解决了问题。

{
  "extends": "./tsconfig.base.json"
}