2

I'm trying to set up a component in Angular 2 with Typescript using Visual Studio Code for Mac. When I use the following code, I get these errors: duplicate identifier 'Component'. and Duplicate identifier' DashboardComponent'.

import {Component} from 'angular2/core';

@Component({
   selector: 'dashboard',
   templateUrl: './dashboard.component.html'
})

export class DashboardComponent {

}

My file structure looks like this:

app
-dashboard
--dashboard.component.html
--dashboard.component.ts
-app.component.html
-app.component.ts
-main.ts
index.html

I'm not exporting the class DashboardComponent anywhere else in the code.

I'm not sure if this is a Visual Studio Code issue or a Typescript/Angular2 issue. Any idea what I'm doing wrong here?

1
  • 1
    Paste your tsconfig.json file. Commented Feb 28, 2016 at 6:56

1 Answer 1

7

The common reason for such problems is that you do have that identifier exported several times in your project (that is everything under project root dir) somewhere in d.ts files deep nested in folder structure. To eliminate such error the usual route is to exclude 'node_modules' and (if you use typings) 'browser' or 'main' typings folder leaving just one. That is done by using "exclude" section of tsconfig.json. Having said that the typical tsconfig will look something like this:

{ 
    "compilerOptions": { 
    },
    "exclude": [
        "node_modules",
        "dist",
        "typings/browser.d.ts",
        "typings/browser/**"
    ]
} 

Hope this helps.

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

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.