1

I am upgrading an Angular project (created with Angular CLI) from 2 to 4. I have followed the upgrade instructions, but now the project does not compile, due to type errors like this one:

ERROR in /mypath/node_modules/typescript/lib/lib.dom.d.ts (6945,11): 
Duplicate identifier 'Headers'.

To debug, I created a fresh Angular 4 project, again with the CLI, to compare against. The newly created project compiles without errors.

When I compre the file in question (lib.dom.d.ts), they are exactly the same, but in the upgraded project, the error is highlighted in VS Code, but not in the new project (left is upgraded, right is new project):

compare

(interestingly, I have a lot of red indicators in the new project's scroll area, what are they trying to tell me?)

I thought I could figure out what the differences are between those two projects to fix the issue, but I'm not finding any.

Both projects return

./node_modules/tslint/bin/tslint -v
4.5.1

./node_modules/typescript/bin/tsc -v
Version 2.2.1

ng -v
@angular/cli: 1.0.0
node: 7.4.0
os: darwin x64
@angular/animations: 4.0.0
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/compiler-cli: 4.0.0
@angular/core: 4.0.0
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/platform-server: 4.0.0
@angular/router: 4.0.0
@angular/cli: 1.0.0

tsconfig.json are the same:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "baseUrl": "src",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2016",
      "dom"
    ]
  }
}

So the question: what else could be causing the difference in behaviour?

1
  • check out if the version of core-js is the same. does removing 'dom' from "lib" in tsconfig do anything? Commented Mar 25, 2017 at 15:08

3 Answers 3

1

Make sure in your package.json the typescript version is 2.1.x or more.

"typescript": "~2.1.0"

see this link if it helps: angular2 -> 4

Sign up to request clarification or add additional context in comments.

Comments

0

For the benefit of searchers, if you are using Visual Studio 2015, you may also need the 'Typescript 2.2 Extension for Visual Studio 2015' to get the typescript compiling nicely.

enter image description here

Comments

0

For reference, the issue was that I had 'typescript' in both dependencies and devDependencies in package.json. Removing it from dependencies fixed the issue.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.