2017-07-27 135 views
11

我正在使用Typescript 2.4.1并升级了许多包在我的项目中。其中我将Angular从2升级到4.3.1。 在@types包许多更正后,我留下的错误是:错误TS2304:生成:升级到Angular 4后找不到名称'Iterable'

\node_modules\@types\jquery\index.d.ts(2955,63): error TS2304: Build:Cannot find name 'Iterable'. 
\node_modules\@types\three\three-core.d.ts(767,24): error TS2304: Build:Cannot find name 'Iterable'. 
\node_modules\@types\three\three-core.d.ts(771,24): error TS2304: Build:Cannot find name 'Iterable'. 
\node_modules\@types\three\three-core.d.ts(775,24): error TS2304: Build:Cannot find name 'Iterable'. 
\node_modules\@types\three\three-core.d.ts(779,24): error TS2304: Build:Cannot find name 'Iterable'. 
\node_modules\@types\three\three-core.d.ts(783,24): error TS2304: Build:Cannot find name 'Iterable'. 
\node_modules\@types\three\three-core.d.ts(787,24): error TS2304: Build:Cannot find name 'Iterable'. 
\node_modules\@types\three\three-core.d.ts(791,24): error TS2304: Build:Cannot find name 'Iterable'. 
\node_modules\@types\three\three-core.d.ts(795,24): error TS2304: Build:Cannot find name 'Iterable'. 
\node_modules\@types\three\three-core.d.ts(799,24): error TS2304: Build:Cannot find name 'Iterable'. 

我发现有很多类似的问题和答案以及现行的解决方案是针对“ES2015”和/或添加lib目录下:[” dom“,”es2015“,”es2015.iterable“]。 我试过所有这些和更多,但仍然留下了相同的'Iterable'错误。

我的更新tsconfig.json是这样的:

{ 
    "compileOnSave": true, 
    "compilerOptions": { 
     "declaration": false, 
     "emitDecoratorMetadata": true, 
     "experimentalDecorators": true, 
     "lib": [ "dom", "dom.iterable", "es2015", "es2015.iterable", "esnext" ], 
     "module": "commonjs", 
     "moduleResolution": "node", 
     "noImplicitAny": true, 
     "noEmitOnError": true, 
     "outDir": "./wwwroot/js", 
     "removeComments": false, 
     "rootDir": "./Client", 
     "sourceMap": true, 
     "suppressImplicitAnyIndexErrors": true, 
     "target": "es2015", 
     "typeRoots": [ 
      "./node_modules/@types", 
      "./Client" 
     ] 
    }, 
    "exclude": [ 
     "node_modules", 
     "wwwroot/lib" 
    ], 
    "filesGlob": [ 
     "./Client/**/*.ts" 
    ] 
} 

我的package.json是:

{ 
    "version": "1.0.0", 
    "name": "web-server", 
    "private": true, 
    "dependencies": { 
     "@angular/common": "^4.3.1", 
     "@angular/compiler": "^4.3.1", 
     "@angular/core": "^4.3.1", 
     "@angular/forms": "^4.3.1", 
     "@angular/http": "^4.3.1", 
     "@angular/platform-browser": "^4.3.1", 
     "@angular/platform-browser-dynamic": "^4.3.1", 
     "@angular/router": "^4.3.1", 
     "@angular/upgrade": "^4.3.1", 
     "bootstrap": "3.3.7", 
     "core-js": "2.4.1", 
     "lodash": "4.17.4", 
     "pixi.js": "4.5.4", 
     "reflect-metadata": "0.1.10", 
     "rxjs": "^5.4.2", 
     "systemjs": "0.20.17", 
     "three": "0.86.0", 
     "zone.js": "0.8.14" 
    }, 
    "devDependencies": { 
     "@types/chai": "^4.0.1", 
     "@types/jquery": "3.2.9", 
     "@types/lodash": "4.14.71", 
     "@types/mocha": "2.2.41", 
     "@types/pixi.js": "4.5.2", 
     "@types/three": "0.84.19", 
     "bower": "^1.8.0", 
     "gulp": "3.9.1", 
     "gulp-clean": "^0.3.2", 
     "gulp-concat": "^2.6.1", 
     "gulp-typescript": "^3.2.1", 
     "gulp-inline-ng2-template": "^4.0.0", 
     "gulp-sourcemaps": "^2.6.0", 
     "gulp-tsc": "^1.3.2", 
     "gulp-uglify": "^3.0.0", 
     "merge2": "^1.1.0", 
     "path": "^0.12.7", 
     "rimraf": "^2.6.1", 
     "systemjs-builder": "^0.16.9", 
     "typescript": "2.4.1" 
    }, 
    "scripts": { 
     "gulp": "gulp", 
     "rimraf": "rimraf", 
     "bundle": "gulp bundle", 
     "postbundle": "rimraf dist" 
    } 
} 

岂是 “迭代” 所有那些LIB夹杂物后,没有发现? Typescript编译器不会忽略我的tsconfig.json,因为更改某些选项会给出各种输出,但不会出现错误。

我的环境是使用Typescript工具2.4.1的Visual Studio 2015更新3。 我正在使用npn @types(无类型)。 详细的编译输出显示Visual Studio有效地使用了2.4.1版本。

最奇怪的是,使用相同的Typescript版本和tsconfig编译使用gulp不会导致错误。

+0

你确定你没有在你的应用程序在其他地方冗余tsconfig.json或tsconfig.app.json文件被覆盖的一个或多个的那些设置?发生过一次...... – diopside

+1

是的。我终于跳到VS2017(我最初不想),没有升级打字稿,现在一切都很好。 –

回答

1

升级我的整个环境,而不是项目,伎俩。 我升级到VS2017,现在一切正常编译。

我的安装可能存在腐败,尽管除了VS2015之外,我几乎可以重新安装任何东西。

谢谢大家的帮助。

10

这看起来非常有什么这里描述:

https://github.com/DefinitelyTyped/DefinitelyTyped/issues/16939

因此,无论尝试使用

"target": "es6" 

与那里描述 - 或者是什么为我们工作:

"target": "es5", 
"lib": ["es2016","dom"] 
+2

我已经遇到这个帖子,并尝试了两种解决方案,但它导致了相同的结果。顺便说一句“es6”应该和“es2015”一样。 –

0

更新:溶胶下面的解释对我造成了部署问题。更好的解决方案是只从解决方案中排除node_modules文件夹中的所有tsconfig.json文件。似乎与this Visual Studio问题有关。

我对Visual Studio和TypeScript的版本有类似的问题。在Visual Studio Code中一切都按预期工作。我尝试了其他发布的建议无济于事......唯一解决的办法是从我的项目中排除node_modules文件夹,但将其留在解决方案中。

0

最近遇到这个问题时,谷歌搜索我的问题,没有一个解决了我的问题。我不得不做一些挖掘,但最后发现,我只好包括ES6定义文件到我的根打字稿文件的顶部:

///<reference path="./node_modules/typescript/lib/lib.es6.d.ts"/> 
12

“可迭代”为节点的分型文件中定义。安装为我解决问题的文件(node_modules/@types/node/index.d.ts)。

NPM安装@类型/节点--save-dev的

+1

这也是为我工作的解决方案。看来问题在于,当前(撰写本文)版本的来自absolutelytyped.org的jQuery typings文件包含以下行:'引用节点的接口JQuery extends Iterable '但它不'实际上引用了node.d.ts类型定义。 –

+0

@BradWestness,这正是原因。感谢您终于找到问题的根源。 – Trygve

相关问题