为什么我得到这个和更多类似的错误?我正在添加一个链接到回购以及下面的关键代码片段。我认为我对依赖和“包括”链接的工作方式有一个基本的误解。

csvproc(master)> tsc
node_modules/typescript/bin/lib.core.d.ts(83,5): error TS2300: Duplicate identifier 'configurable'.
node_modules/typescript/bin/lib.core.d.ts(84,5): error TS2300: Duplicate identifier 'enumerable'.
node_modules/typescript/bin/lib.core.d.ts(85,5): error TS2300: Duplicate identifier 'value'.
node_modules/typescript/bin/lib.core.d.ts(86,5): error TS2300: Duplicate identifier 'writable'.

所有代码都可以在这里找到。

我的tsconfig.json:

{
    "compilerOptions": {
        "module": "commonjs",
        "noImplicitAny": false,
        "outDir": "built/",
        "sourceMap": true,
        "target": "es5"
    }
}

我的tsd.json:

{
  "version": "v4",
  "repo": "borisyankov/DefinitelyTyped",
  "ref": "master",
  "path": "typings",
  "bundle": "typings/tsd.d.ts",
  "installed": {
    "node/node-0.10.d.ts": {
      "commit": "6387999eb899d0ba02d37dd8697647718caca230"
    },
    "should/should.d.ts": {
      "commit": "e1182d56ccb192379eade6055d9ba3fb6a0bacc4"
    }
  }
}

我的tsd.d.ts:

{
  "version": "v4",
  "repo": "borisyankov/DefinitelyTyped",
  "ref": "master",
  "path": "typings",
  "bundle": "typings/tsd.d.ts",
  "installed": {
    "node/node-0.10.d.ts": {
      "commit": "6387999eb899d0ba02d37dd8697647718caca230"
    },
    "should/should.d.ts": {
      "commit": "e1182d56ccb192379eade6055d9ba3fb6a0bacc4"
    }
  }
}

当前回答

简单地解决问题:

删除“node_modules”文件夹 运行npm install获取所有版本正确的包

在我的例子中,问题发生在更改Git分支之后,其中一个新分支使用了一组不同的节点模块。旧分支使用的是TypeScript v1.8,新分支使用的是TypeScript v2.0

其他回答

我刚刚遇到了这个问题。当我运行npm start时,我得到了一堆重复的标识符错误。

解决方案:

从项目根文件夹运行:

rm -r typings
typings install
npm start

一切都很正常。

这可能是因为节点文件夹中同时存在类型和依赖项。 因此,首先检查你的@types文件夹中有什么,如果你有依赖项,删除重复项。 对我来说是core.js

添加"skipLibCheck": true到"compilerOptions"

https://github.com/ionic-team/capacitor/issues/5436#issuecomment-1077942409

Angular的一个(可能的)解决方案

在我的例子中,当安装@angularfire。它会自动从我的环境文件中导入环境。这给出了重复标识符“环境”错误。

但是,我已经在同一个文件中导入了这个文件,因此导致了重复标识符错误。

我创建了一个新项目,一步一步地找到这个错误……

TL;DR:检查文件中的重复导入,出现错误。

如果你已经在typings文件夹中单独安装了类型,将其添加到tsconfig.json:

{
  "exclude": [
    "node_modules",
    "typings"
  ]
}