@Types/node/index.d.ts TypeScript 错误 TS2309
Posted
技术标签:
【中文标题】@Types/node/index.d.ts TypeScript 错误 TS2309【英文标题】:@Types/node/index.d.ts TypeScript Error TS2309 【发布时间】:2017-04-05 03:57:42 【问题描述】:我有一个使用 SystemJs 的 .Net Core Angular 2 项目,我最近从 Typings 升级到 @Types。
截至 2016 年 12 月 21 日,该项目已使用适用于 .Net Core 1.0.1 和 TypeScript 2.0.10 和 Node.js 7.0.0 的最新 VS 工具完全重建。
项目文件在更新到 @Types 之前工作正常。
我从@Types/node/index.d.ts 收到以下错误:
TS2309 “构建:导出分配不能在具有其他导出元素的模块中使用。” 3626行
@Types/node/index.d.ts 的第 3626 行是“断言”模块声明的导出。
这是我的配置文件
tsconfig.json
"compilerOptions":
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"skipLibCheck": true
,
"compileOnSave": true,
"exclude": [
"node_modules",
"wwwroot/shared/lib"
]
包.json
"name": "angular-quickstart",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts":
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"lite": "lite-server",
"tsc": "tsc",
"tsc:w": "tsc -w"
,
"keywords": [],
"author": "",
"license": "ISC",
"dependencies":
"@angular/common": "~2.2.0",
"@angular/compiler": "~2.2.0",
"@angular/core": "~2.2.0",
"@angular/forms": "~2.2.0",
"@angular/http": "~2.2.0",
"@angular/platform-browser": "~2.2.0",
"@angular/platform-browser-dynamic": "~2.2.0",
"@angular/router": "~3.2.0",
"@angular/upgrade": "~2.2.0",
"angular-in-memory-web-api": "~0.1.15",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.41",
"zone.js": "^0.6.26",
"@progress/kendo-angular-grid": "^0.6.1",
"@progress/kendo-angular-charts": "^0.9.0",
"@progress/kendo-angular-dropdowns": "^0.16.10",
"@progress/kendo-angular-inputs": "^0.13.1",
"@progress/kendo-angular-layout": "^0.15.0",
"@progress/kendo-angular-dialog": "^0.12.2",
"@progress/kendo-angular-upload": "^0.10.4",
"@progress/kendo-angular-buttons": "^0.13.3",
"@progress/kendo-angular-popup": "^0.13.2",
"@progress/kendo-angular-scrollview": "^0.5.1",
"@progress/kendo-angular-sortable": "^0.5.1",
"@progress/kendo-data-query": "^0.1.6",
"@telerik/kendo-theme-default": "^1.28.1",
"jquery": "2.1.1",
"jquery-validation": "1.15.1",
"jquery-validation-unobtrusive": "3.2.6",
"office-ui-fabric-core": "5.0.1",
"bootstrap": "3.3.7"
,
"devDependencies":
"@types/core-js": "^0.9.34",
"@types/node": "^6.0.49",
"@types/jasmine": "2.5.38",
"concurrently": "^3.0.0",
"lite-server": "^2.2.2",
"typescript": "^2.0.10",
"gulp": "3.9.1",
"gulp-cssmin": "0.1.7",
"gulp-concat": "2.6.0",
"gulp-uglify": "2.0.0",
"gulp-clean": "0.3.2",
"gulp-typescript": "2.14.1"
,
"repository":
【问题讨论】:
您的项目中是否有typings.json 文件和typings 文件夹,或者您是否更改或删除了这些? 我在没有安装 Typings 的情况下重新创建了项目,因此没有 Typings 文件夹或 Typings.json 文件。在安装 Typings 的原始项目中,我确实尝试删除文件以避免重复,但最终得到了相同的错误 TS2309,这促使我从头开始只是为了确保。我没有收到任何“重复标识符”错误。 【参考方案1】:来自 GitHub 上 TypeScript 人员的建议已为我们修复。
搜索以下内容 -
declare module "assert"
它应该只在您的项目中出现一次。我们将它放在两个文件中——@types/node 包中的 TypeScript 定义文件和我们 wwwroot 文件夹中的第二个文件,该文件需要删除并被 Gulp 任务错误地复制并被编译器拾取。希望这会有所帮助!
【讨论】:
果然,reflect-metadata 包含一个 typings 文件夹,里面有一个声明“assert”的 node.d.ts 文件。我无法删除该文件,因为编译器抱怨它找不到它,但是注释掉声明修复了问题并且项目再次没有错误。谢谢!以上是关于@Types/node/index.d.ts TypeScript 错误 TS2309的主要内容,如果未能解决你的问题,请参考以下文章
ERROR in D:/project/node_modules/@types/node/index.d.ts (20,1): Invalid‘ reference‘ directive syntax