Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate identifiers #6489

Closed
bartvanderwal opened this issue Jan 14, 2016 · 9 comments
Closed

Duplicate identifiers #6489

bartvanderwal opened this issue Jan 14, 2016 · 9 comments
Labels
Duplicate An existing issue was already created

Comments

@bartvanderwal
Copy link

I'm experiencing a lot of Duplicate identifiers errors. I see around 80 similar issues, but I don't see a clear and workable solution anywhere. Not on stackoverflow neither.

I'm using current Typescript, e.g. tsc v1.7.5. The exclude option in tsconfig does not seem to be respected, as I get around a 100 Duplicate identifier issues when compiling. All in the typings folders. See below. Before I had similar errors in node_modules files, but they seem to have disappeared after adding node_modules in my tsconfig's exclude. But similarly adding typings (and client/typings) does NOT fix this issue.

I'm currently using - only - this in a few of my own .ts. But most don't have any at all. At least NOwhere am I referencing int

 /// <reference path="typings/tsd.d.ts" />

Can you give advice how to solve this? Or is this a temporary bug to be fixed?

I already switched to Visual Studio Code and manual compiling instead of compile on save in Visual Studio with Node Tools for VS, because NTVS kept stalling the UI for dozens of seconds, killing any programmer flow 😢 . I find this typescript potentially very cool and powerful, but practically currently a bit unworkable 😭.

tsd.json

{
    "compilerOptions": {
        "module": "commonjs",
        "noImplicitAny": false,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "target": "es5"
    },
    "exclude": [
        "node_modules",
        "bower_components",
        "typings",
        "client/typings"
    ]
}

Sample from error output

client/typings/underscore/underscore.d.ts(53,3): error TS2374: Duplicate string index signature.
client/typings/underscore/underscore.d.ts(1693,2): error TS2300: Duplicate identifier 'templateSettings'.
client/typings/underscore/underscore.d.ts(3628,2): error TS2300: Duplicate identifier 'export='.
typings/mocha/mocha.d.ts(8,5): error TS2300: Duplicate identifier 'slow'.
typings/mocha/mocha.d.ts(11,5): error TS2300: Duplicate identifier 'timeout'.
typings/mocha/mocha.d.ts(14,5): error TS2300: Duplicate identifier 'ui'.
typings/mocha/mocha.d.ts(17,5): error TS2300: Duplicate identifier 'globals'.
typings/mocha/mocha.d.ts(20,5): error TS2300: Duplicate identifier 'reporter'.
@mhegazy
Copy link
Contributor

mhegazy commented Jan 14, 2016

looks like a duplicate of #6475 (no pun intended :))

@mhegazy
Copy link
Contributor

mhegazy commented Jan 14, 2016

can you provide more details on your setup?

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jan 14, 2016
@bartvanderwal
Copy link
Author

Setup? What do you want to know, besides what I specified already? :)

It's a Node project with angular on the frontend. Angular 1.x, NOT 2, like #6475. But like that issue I'm also using some npm/tsd projects both on server and on client side. And the errors seem to come from mocha, node and underscore). I actually don't know why the node.d.ts is on the client side also, it was like that when I entered the project, so I removed that for now. And Mocha also (only serverside tests so far). But there is still underscore that we need to use on both ends. I even already tried to use lodash on client and underscore on server, but that actually gives the same nameclashes (logical in hindsight, they're API compatible).

It ran/runs fine in Visual Studio, but when I run it with NodeMon (via Grunt task) I get this sh@#load of 'duplicate' errors.

I'm NOT using browserify, so to keep things simple for now, I have not deduplicated them. I just want one used with CommonJS and one with AMD. On the client we're still on a completely flat structure, using no ES modules client side (only using Angular's modules).

Everything is in one (NTVS) project.

I could try to make a more minimal recreation and put it it a public repo. That'll take some time though. I was hoping I could be productive sooner :).

@mhegazy
Copy link
Contributor

mhegazy commented Jan 15, 2016

duplicate declarations means you have two declarations for the same entity :). so you have two references to mocha.d.ts, removing one should stop the errors.

If i can look at the project i might have a better answer.

@bartvanderwal
Copy link
Author

Okay. Well that's a clear statement. There ARE 2 tsd.d.tsfiles, one in typings/ folder (for server-side) and one in client/typings.

As explained I already remove node and mocha projects from the client, and if I now also remove the included underscore typing:

/// <reference path="underscore/underscore.d.ts" />

from the client/typings/ts, then the compile errors I mentioned are gone.

I then don't get unknown type or other similar compile errors in the client side ts as I expected. So I guess it then just uses the definitions from the root typings folder. Thought there are NO references to it (e.g /// like before).

I would have expected that in my regular .ts script I would have to use something like at the top

/// <reference path="../typings/tsd.d.ts" />
/// <reference path="../../typings/tsd.d.ts" />

to reference both client and server side scripts, instead of client only..

@bartvanderwal
Copy link
Author

@mhegazy can I have two tsconfig files in one project? One for server and one for client? It's unclear to me from the documentation.

Because the server should have CommonJS target. The client side is just 'globals' for now, though target AMD seems the only option available for client side. But for now I'm reluctant to take on yet another dependency on requirejs, as the project feels so flakey.

@ambition-consulting
Copy link

This error is so annoying, why can I not just turn it off? I can effectively no longer use the tsc error messages in my IDE directly, and instead have to rely on my gulp output.

@mhegazy
Copy link
Contributor

mhegazy commented Feb 18, 2016

@bartvanderwal sorry for the delay, just saw this now.

With TypeScript 1.8, you should be able to have multiple TSConfig files in your project, and it should split your files into islands. see https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#improved-support-for-tsconfigjson-in-visual-studio-2015 for more details.

@mhegazy mhegazy closed this as completed Feb 20, 2016
@LordDelacroix
Copy link

I'm getting these same errors in a classic ASP.NET 4.6.1 solution that doesn't even USE Typescript when compiling under VS2017!!

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants