运行angular 2项目时出现许多TS2X错误

时间:2018-08-25 22:22:01

标签: angular typescript rxjs

运行我的角度项目时遇到错误。我最近将ts1更新为ts2。我在项目angular 2和打字稿中使用。这是我的项目技术:

Angular CLI: 6.1.5
Node: 8.11.4
OS: win32 x64
Angular: 2.4.10
... common, compiler, core, forms, http, platform-browser
... platform-browser-dynamic, platform-server, upgrade

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.7.5
@angular-devkit/core         0.7.5
@angular-devkit/schematics   0.7.5
@angular/cli                 6.1.5
@angular/router              6.1.4
@schematics/angular          0.7.5
@schematics/update           0.7.5
rxjs                         5.5.11
typescript                   2.9.2

The stack error looks like the following:
    myProject/node_modules/@angular/compiler/src/aot/static_reflector.d.ts(8,49): error TS2422: A class may only implement another class or interface.
    myProject/node_modules/@angular/core/src/testability/testability.d.ts(41,33): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/core/src/util/decorators.d.ts(11,5): error TS2411: Property 'extends' of type 'Type<any> | undefined' is not assignable to string index type 'Function | any[] | Type<any>'.
    myProject/node_modules/@angular/forms/src/directives/ng_form.d.ts(62,22): error TS2304: Cannot find name 'Event'.
    myProject/node_modules/@angular/forms/src/directives/reactive_directives/form_group_directive.d.ts(75,22): error TS2304: Cannot find name 'Event'.
    myProject/node_modules/@angular/http/src/base_response_options.d.ts(35,43): error TS2304: Cannot find name 'Blob'.
    myProject/node_modules/@angular/http/src/body.d.ts(21,13): error TS2304: Cannot find name 'Blob'.
    myProject/node_modules/@angular/http/src/interfaces.d.ts(69,30): error TS2304: Cannot find name 'FormData'.
    myProject/node_modules/@angular/http/src/interfaces.d.ts(69,55): error TS2304: Cannot find name 'Blob'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(11,26): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(12,21): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(13,21): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(14,16): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(21,23): error TS2304: Cannot find name 'Element'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(21,51): error TS2304: Cannot find name 'HTMLElement'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(23,12): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(24,21): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(25,23): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(26,42): error TS2304: Cannot find name 'MouseEvent'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(27,34): error TS2304: Cannot find name 'Event'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(28,25): error TS2304: Cannot find name 'Event'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(29,22): error TS2304: Cannot find name 'Event'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(30,22): error TS2304: Cannot find name 'HTMLElement'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(31,28): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(31,35): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(32,22): error TS2304: Cannot find name 'HTMLElement'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(33,20): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(34,21): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(35,16): error TS2304: Cannot find name 'HTMLInputElement'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(36,19): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(36,26): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(37,20): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(37,27): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(38,21): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(38,28): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(39,23): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(39,30): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(40,26): error TS2304: Cannot find name 'Node'.
    myProject/node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(41,26): error TS2304: Cannot find name 'Node'.

经过一些研究,由于tsconfig.json,有些人也遇到了同样的问题,建议添加es6 lib,但我行不通。

有什么主意吗?谢谢

1 个答案:

答案 0 :(得分:0)

在您的tsconfig.json文件中尝试添加以下内容:

  "compilerOptions": {

"lib": [
  "es2017",
  "dom"
]

}