2016-11-16 51 views
0

昨天我遇到了一个与我的NS NG2应用程序的问题。每当我尝试运行命令 - tns livesync android --watch或任何其他命令来构建。我收到了很长的错误列表。下面是这个错误的一小部分。Typescript - 重复的标识符

app/node_modules/typescript/lib/lib.es6.d.ts(20054,15): error TS2451: Cannot red 
eclare block-scoped variable 'name'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20328,6): error TS2300: Duplicate i 
dentifier 'AAGUID'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20329,6): error TS2300: Duplicate i 
dentifier 'AlgorithmIdentifier'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20330,6): error TS2300: Duplicate i 
dentifier 'ConstrainBoolean'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20331,6): error TS2300: Duplicate i 
dentifier 'ConstrainDOMString'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20332,6): error TS2300: Duplicate i 
dentifier 'ConstrainDouble'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20333,6): error TS2300: Duplicate i 
dentifier 'ConstrainLong'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20334,6): error TS2300: Duplicate i 
dentifier 'CryptoOperationData'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20335,6): error TS2300: Duplicate i 
dentifier 'GLbitfield'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20336,6): error TS2300: Duplicate i 
dentifier 'GLboolean'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20337,6): error TS2300: Duplicate i 
dentifier 'GLbyte'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20338,6): error TS2300: Duplicate i 
dentifier 'GLclampf'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20339,6): error TS2300: Duplicate i 
dentifier 'GLenum'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20340,6): error TS2300: Duplicate i 
dentifier 'GLfloat'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20341,6): error TS2300: Duplicate i 
dentifier 'GLint'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20342,6): error TS2300: Duplicate i 
dentifier 'GLintptr'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20343,6): error TS2300: Duplicate i 
dentifier 'GLshort'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20344,6): error TS2300: Duplicate i 
dentifier 'GLsizei'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20345,6): error TS2300: Duplicate i 
dentifier 'GLsizeiptr'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20346,6): error TS2300: Duplicate i 
dentifier 'GLubyte'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20347,6): error TS2300: Duplicate i 
dentifier 'GLuint'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20348,6): error TS2300: Duplicate i 
dentifier 'GLushort'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20349,6): error TS2300: Duplicate i 
dentifier 'IDBKeyPath'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20350,6): error TS2300: Duplicate i 
dentifier 'KeyFormat'. 
app/node_modules/typescript/lib/lib.es6.d.ts(20351,6): error TS2300: Duplicate i 
dentifier 'KeyType'. 

这只是一个非常小的样本,我收到的错误。为了给人留下深刻的印象,当我在我的Mac上工作时发生了这种情况,意识到我需要做的比预期的要多。所以转移到我的电脑,我更熟悉电脑。我拉了我做的小代码更改(已经试图扭转这些)并尝试构建。那是当我遇到这个错误列表。我将在下面列出一些可能有助于找到答案的文件。

的package.json

{ 
    "description": "AppName", 
    "license": "SEE LICENSE IN <your-license-filename>", 
    "readme": "AppName", 
    "repository": "myRepo", 
    "nativescript": { 
    "id": "org.nativescript.appName", 
    "tns-ios": { 
     "version": "2.4.0" 
    }, 
    "tns-android": { 
     "version": "2.4.0" 
    } 
    }, 
    "dependencies": { 
    "@angular/common": "2.1.2", 
    "@angular/compiler": "2.1.2", 
    "@angular/core": "2.1.2", 
    "@angular/forms": "2.1.2", 
    "@angular/http": "2.1.2", 
    "@angular/platform-browser": "2.1.2", 
    "@angular/platform-browser-dynamic": "2.1.2", 
    "@angular/platform-server": "^2.0.0", 
    "@angular/router": "3.1.2", 
    "email-validator": "^1.0.7", 
    "nativescript-angular": "1.1.3", 
    "nativescript-drop-down": "^1.3.3", 
    "nativescript-loading-indicator": "^2.2.1", 
    "nativescript-permissions": "^1.2.1", 
    "nativescript-plugin-firebase": "^3.7.1", 
    "nativescript-telerik-ui": "^1.4.1", 
    "nativescript-toasty": "^1.1.0", 
    "reflect-metadata": "~0.1.8", 
    "tns-core-modules": "2.4.0", 
    "tns-platform-declarations": "^2.0.0" 
    }, 
    "devDependencies": { 
    "babel-traverse": "6.19.0", 
    "babel-types": "6.19.0", 
    "babylon": "6.11.0", 
    "lazy": "1.0.11", 
    "filewalker": "0.1.2", 
    "nativescript-dev-typescript": "^0.3.2", 
    "typescript": "^2.0.10", 
    "zone.js": "~0.6.21" 
    } 
} 

references.d.ts

/// <reference path="./node_modules/tns-core-modules/tns-core-modules.d.ts" /> Needed for autocompletion and compilation. 
/// <reference path="./node_modules/nativescript-plugin-firebase/index.d.ts" /> 
/// <reference path="./node_modules/tns-core-modules/tns-core-modules.es6.d.ts" /> 

/// <reference path="./node_modules/tns-platform-declarations/ios/ios.d.ts" /> 
/// <reference path="./node_modules/tns-platform-declarations/android/android17.d.ts" /> 

/// <reference path="./node_modules/tns-platform-declarations/android/org.nativescript.widgets.d.ts" /> 

tsconfig.json

{ 
    "compilerOptions": { 
     "module": "commonjs", 
     "target": "es5", 
     "sourceMap": true, 
     "experimentalDecorators": true, 
     "emitDecoratorMetadata": true, 
     "noEmitHelpers": true, 
     "noEmitOnError": true, 
     "lib": [ 
      "es2016" 
     ] 
    }, 
    "exclude": [ 
     "node_modules", 
     "platforms" 
    ] 
} 

如果有任何其他的文件,我可以张贴,可以帮助请让我知道。我相信问题在于其中一个文件。我尝试了所有我能想到的东西,并且只是出于想法。希望你们中的一个人有某种想法!先进的感谢

回答

0

它看起来像你的其他一些文件包括参考node_modules/typescript/lib/lib.es6.d.ts和其他.d.ts文件。我试着重新创建一个基于你的package.json和tsconfig.json的新创建的项目,但不管我的配置如何,lib.es6.d.ts从未包含在转译中。

你应该检查你所有的文件以参考.d.ts文件node_modules。看起来他们中的一些人相互冲突。

您也可以尝试删除您的node_modules目录并再次执行tns build android

还有一个注意事项 - tns-platform-declarations应该是devDependency - 它只用于自动完成和转译,你不需要它在设备上。

+0

我很惊讶,你不能重复的问题。我已经做了。使用tns创建一个项目,创建appname --ng,然后放入我的ref和包文件,它有完全相同的问题。但是我一直无法弄清楚这些文件导致这个 –

0

这可能是你正在引用的其中一个参考是导出与es6类型内置冲突的es6类型。

拿出引用注释,看看你是否仍然有重复的标识符问题。

也尝试取出lib:[“es6”],因为别的东西已经在导入es6类型了。

新版本的typescript可以从npm模块加载类型,如果它们是导出。

您可以在您的compilerOptions中设置moduleResulotion: "node",并使用es6导入来在项目的不同部分加载.d.ts文件。

+0

错误TS5023:未知的编译器选项'moduleResulotion'。 - 尝试你最后的想法时 –

0

解决 -

所以要解决这个问题,我通过我的package.json的每一行去,抬头每个模块。检查他们最近的更新并将其设置为安装大约20天前最后更新的版本。为每一个。删除我的节点模块并执行npm install 4次后。有效。