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 identifier error for d.ts files in Visual Studio 2017 #14565

Closed
odrozd opened this issue Mar 9, 2017 · 96 comments
Closed

Duplicate identifier error for d.ts files in Visual Studio 2017 #14565

odrozd opened this issue Mar 9, 2017 · 96 comments
Labels
Bug A bug in TypeScript

Comments

@odrozd
Copy link

odrozd commented Mar 9, 2017

TypeScript Language Version: 2.2
Visual Studio Typescript tooling Version 2.1.5

I am having trouble with typescript errors like TS2300: duplicate identifier 'export=' and TS2374: Duplicate string index signature. This errors appear in error window, but projects builds successful. This errors appear only with VS2017.

Env Details:

  1. Type definitions are installed via nuget to default folder: project root/scripts/typings/

  2. For build I use nuget package Microsoft.TypeScript.MSBuild" version="2.2.1

  3. tsconfig is NOT used**, instead here are setting from csproj:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptJSXEmit>None</TypeScriptJSXEmit>
    <TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
    <TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
    <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
    <TypeScriptRemoveComments>False</TypeScriptRemoveComments>
    <TypeScriptOutFile>
    </TypeScriptOutFile>
    <TypeScriptOutDir />
    <TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
    <TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
    <TypeScriptSourceMap>True</TypeScriptSourceMap>
    <TypeScriptMapRoot />
    <TypeScriptSourceRoot />
    <TypeScriptStrictNullChecks>false</TypeScriptStrictNullChecks>
    <TypeScriptNoFallthroughCasesInSwitch>true</TypeScriptNoFallthroughCasesInSwitch>
    <TypeScriptLib>dom,es5,es2015.promise</TypeScriptLib>
  </PropertyGroup>

I assume I see this errors because VS2017 somehow downloaded @types to this folder: ~\AppData\Local\Microsoft\TypeScript\node_modules@types\ and there is conflict between this types definitions and those types installed via nuget, if this is the cause I am not sure how disable this feature in VS2017 and honor only nuget installed d.ts?

I would appreciate any help to this issue.

Here is screenshot:
vs2017_typescript_error

@mhegazy
Copy link
Contributor

mhegazy commented Mar 9, 2017

Can you share your project file? or steps to reproduce this behavior?

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Mar 9, 2017
@odrozd
Copy link
Author

odrozd commented Mar 9, 2017

I can share stripped proj file with only typescript related information, not sure if it helps.
IssueVS2017csproj.zip

Regarding steps to reproduce, there isn't I just open VS and in 20-30 seconds I start see this errors in error window, please note project builds successful, VS point to this errors in d.ts files. Also my team-members also have this issue with vs2017.

Another screenshot:
vs2017_typescript_error2

Also I will try to create project from scratch with similar settings and check if this issue exist.

@Serivy
Copy link

Serivy commented Mar 10, 2017

I was just about to add a new issue but I believe this is the same issue I am having. I have managed to replicate it in a simple project (our production project is much more complicated and uses nuget but still suffers from the issue).

To reproduce:

  1. git clone https://github.com/Serivy/TS5055.git
  2. Open TS5055.sln with visual studio 2017.
  3. Compile the project (so that the artefact file1.d.ts is created)
  4. Close visual studio 2017
  5. Open TS5055.sln with visual studio 2017 and open the Error List.
  6. Wait 40 seconds.
  7. The errors should pop up.
    ts5055

I have used each RC build of VS2017 and i can say it was fine until the very last RC (which i think was using the TS2.2 plugin) which i was hoping would be fixed in the release but can confirm i get it in the release as well. This is only for design time as compile time is always correct.

My speculation is that visual studio plugin is sourcing it's own list of files to run through the language service which includes definition files it generates. I have also had it pull .d.ts files from the gulp-typescript package inside a node_modules folder which was listed as exclude in the tsconfig.json.

Any more information required let me know as I have a few cases where this is an issue.

@stewart-r
Copy link

Affected by this too - Agree with @Serivy that it seems to be VS sourcing definition files that conflict with ones already in the solution.

Searching for (find in files) one the duplicate identifiers in my solution throws up the same identifier in the typings inside the solution AND one from ...appdata/Local/Microsoft/Typescript/node_modules/@types/...

@odrozd
Copy link
Author

odrozd commented Mar 10, 2017

I am also can replicate this issue from scratch:

  1. Add new MVC5 project,
  2. Add any ts file
  3. Install jQuery typing via nuget
  4. open тгпуе installed jquery.d.ts file in VS editor or wait 20-30 second

Also if I am manually delete typings from folder: "~\AppData\Local\Microsoft\TypeScript\node_modules@types" errors disappear after several seconds, but when reopen VS this folder populated again causing this errors to appear again.

@UsherNet
Copy link

Same problem has existed with VS2017 since RC. It would be good to a) understand it, b) make it go away!

@ArtemAvramenko
Copy link

Steps to reproduce:

  1. Create ASP.NET Web Application (C#)
  2. Choose MVC template
  3. Install-Package jquery.TypeScript.DefinitelyTyped
  4. Open jquery.d.ts

error

@jurion
Copy link

jurion commented Mar 13, 2017

Same problem with WebForms project.
image

@ArtemAvramenko
Copy link

Another error: Duplicate string index signature
duplicate_string_index
"

@LbISS
Copy link

LbISS commented Mar 15, 2017

The same problem. Just opened solution which worked fine on VS2015 with new VS2017 - can't build, errors:
All declarations of 'iterator' must have identical modifiers.
Duplicate string index signature

@KunleSmart
Copy link

I have same problem as indicated by @LbISS. This also include Error TS2300 Duplicate identifier 'ng'.

@intoxopox
Copy link

Also triggered by cleaning and rebuilding the solution.

@mhegazy mhegazy added Bug A bug in TypeScript and removed Needs More Info The issue still hasn't been fully clarified labels Mar 18, 2017
@mhegazy mhegazy added this to the Visual Studio 15.1 milestone Mar 18, 2017
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Mar 20, 2017
@mhegazy mhegazy self-assigned this Mar 20, 2017
@styfle
Copy link
Contributor

styfle commented Mar 21, 2017

@mhegazy Thanks for the quick fix!
Is there a workaround while we are waiting for the fix to be released?

@odrozd
Copy link
Author

odrozd commented Mar 21, 2017

@mhegazy Could you please clarify that this fix will be available with Visual Studio 2017 Update 1?

@wdunn001
Copy link

wdunn001 commented Apr 3, 2017

So I hope this helps I was also afflicted by this. I had to remove typings from scripts in my package.json then delete the typings folder from

"scripts": {
"postinstall": "typings install",
"typings": "typings"
}

and remove any typings or @types folder from node_module. This can also be cause by having typings installed locally and globally.

@MattFromGer
Copy link

I upgraded to 15.1 (26403.0) today and I still get the errors...

@intoxopox
Copy link

Still happens in 26403.3 as well.

@jjoekoullas
Copy link

jjoekoullas commented Apr 12, 2017

Quick and dirty hack to get around this while waiting for a proper fix:

  1. Comment out all of the devDependencies in %localappdata%\Microsoft\TypeScript\package.json.
    Mine currently looks like:
{
  //"devDependencies": {
  //  "@types/angular": "^1.6.14",
  //  "@types/angular-strap": "^2.2.31",
  //  "@types/angular-ui-router": "^1.1.36",
  //  "@types/bootstrap": "^3.3.32",
  //  "@types/clipboard": "^1.5.33",
  //  "@types/handlebars": "^4.0.32",
  //  "@types/jquery": "^2.0.41"
  //}
}
  1. Make %localappdata%\Microsoft\TypeScript\package.json read-only.
  2. Delete all the folders in %localappdata%\Microsoft\TypeScript\node_modules\@types

After a VS restart, clean, rebuild everything is back to normal (for me at least).

@odrozd
Copy link
Author

odrozd commented Apr 12, 2017

@jjoekoullas I tried this approach, but it appears that after some time or after VS restart, some background process bring back this dependencies to package.json and typings get downloaded again which causes errors to appear again (this was my case)

I am still wondering based on which rules or settings, concrete dev dependencies appear in package.json file, e.g. how typescript know which dependencies I need...

@jjoekoullas
Copy link

@odrozd sorry, forgot to mention to make %localappdata%\Microsoft\TypeScript\package.json read-only

@billti billti removed the Fixed A PR has been merged for this issue label Dec 1, 2017
@ManuelHaas
Copy link

@billti: Excluding knockout from typeAcquisition worked for me. Thanks a lot!

@david-grogan
Copy link

I disabled the @jjoekoullas workaround and disabled typeAcquisition via a .tsconfig and it seems to have fixed the problem for me also (crossing my fingers, the timing on this bug wasn't predictable).

You should also probably add the typeAcquisition option to the project properties (and a default setting to the VS options), for those of us not using a tsconfig.json (not a fan of the profusion of javascript config files, gulp, etc., I just want a single project file).

I don't want VS to be doing stuff like this in the background for me, if I want a reference I'll add it manually.

@rezelute
Copy link

rezelute commented Dec 1, 2017

The error (Duplicate identifier export=) was happening to me randomly and I was managing to get around it by simply re-installing the typing using Nuget Package Manager. Today however, I have installed the latest version of visual studio and this workout no longer applies. There seems to be a conflict between "Scripts/typings/jquery/jquery.d.ts" and "packages/jquery.TypeScript.DefinitelyTyped.3.1.2/Content/Scripts/typings/jquery/jquery.d". Even when i specify in the tsconfig.json the typeRoots to be only [ "Scripts/typings" ], it still doesnt work.

I tried @jjoekoullas fix however it still happens to me. How did you disable typeAcquisition via a .tsconfig?

My project was a website however I have just tested converting it to an application project and it seems to be working better (because the packages folder lives outside the web directory). However, when you install another typing via NuGet (I was using Mustache) then it complains again about "export=".

@david-grogan
Copy link

david-grogan commented Dec 1, 2017

To disable typeAcquisition see @billti's comment above: #14565 (comment)

I just set it like this:

"typeAcquisition": {"enable": false}

@RyanCavanaugh
Copy link
Member

Fix available; PR pending soon

There are actually two issues here:

  • Due to a bug in how we reused program structure, we were wrongly considering knockout to be an unresolved module during cached program rebuilds. PR up soon
  • A separate bug is that the NodeJS project system adds node to the ATA include list even though there may be a local @types/node package in the project folder. The workaround is simple; just add "exclude": ["node"] to the typeAcquisition block in your tsconfig. Logged Duplicate identifier errors when NodeJS project has local copy of @types/node + ATA enabled #20402

@rezelute
Copy link

rezelute commented Dec 6, 2017

But i dont have any node folders in my project, the conflict is happening from the packages folder and the typings one in "Scripts". The strange thing is that it works for a certain period and then when I make changes to some of my TS files, it randomly shows the errors again which means that i can't re-compile (and thus produce my exported JS files).
I have tried the typeAcquisition but still no luck.

If i delete the packages folder, re-compiling works fine however VS complains that I need to restore the node packages.

Any ideas?

untitled

@billti
Copy link
Member

billti commented Dec 6, 2017

You should remove the jquery type definition from under your scripts/typings folder if it already comes via the NuGet package.

@JiriZidek
Copy link

@billti: removing nugetted typings breaks TFS build running on buildserver !
Strange is that I solved this by uninstlalling duplicated packages in npm commandline in March, now after installing it reappeared... I'll try use same medicine...

@rezelute
Copy link

Removing it from typings seems to work fine. The problem is that sometimes the typings folder is coming back for some reason and i have to keep on deleting it. Why is it that when you install the package via nuGet package manager that it installs both the package and the typing?

@JiriZidek
Copy link

It is necessary tu run npm -D --save --save-dev package@name for each offending typing file.
Tricks:

  • you have to run it in scope of %AppData%....\ where the offending file sits, there is one with version 2.6 and one in upper folder
  • by running npm -list you can see what packages npm considers shoudl exist - if you see listed it, it wil download it again, even after you deleted the folder

@rezelute
Copy link

I dont quite understand. I installed the typing via "nuget package manager for solution" not npm. There is no npm usage in the project. So i am guessing that visual studio has npm running in the background which eventually re-downloads it or something when it notices that it is missing.

@JiriZidek
Copy link

TS & VS from some version 2.2 implicitly uses node.js infrastructure (so even you did not install it, you have it) and it uses npm packaging by default. It collides with older "nuget only" apporach.

@tomek14
Copy link

tomek14 commented Jan 10, 2018

Any updates on this? I don't have Intelisense in .js files becouse of this. My project is using TypeScript and JavaScript files, when I set typeAcquisition = true Intelisense in JavaScript files works but in TypeScript i got error of Duplicate Identifier becouse my TypeScript project uses @types to build in CI pipeline. Maybe there is some kind of workaround on this ?

@shelland
Copy link

shelland commented Mar 4, 2018

Is this issue still active? I still have hundreds of build errors for jquery typings (VS 2017 15.5.0, ASP.NET Core 2.0). I'm spending my time fighting with typescript instead of writing my code and i can not continue a work because my JS files are not being generated.

@shelland
Copy link

shelland commented Mar 4, 2018

image

jquery typings were installed using NPM, i didn't user NuGet for this.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 5, 2018

@shelland can u share your project or a sample showing the same behavior?

@a688
Copy link

a688 commented Apr 24, 2018

I was encountering this extremely annoying error recently and setting "typeAcquisition": {"enable": false} fixed it. I am only using TypeScript to process .ts files with plain es5 code in an MVC5 project. I don't see how this is still an issue a year after this was first reported.

@tommai78101
Copy link

tommai78101 commented May 19, 2018

For me I encountered multiple Duplicate identifier "DataTransfer" error messages, emitted from lib.d.ts.

I received this error after I did the following:

  1. Installed latest Node.js and npm globally on a fresh installation of Windows.
  2. Installed the following packages globally:
    babel-eslint
    eslint
    eslint-config-defaults
    eslint-plugin-import
    eslint-plugin-react
  3. Opened a JavaScript project file (company internal project file, aka, non-open source)

I fixed it (or rather, I suppressed the errors) with the following:

//tsconfig.json placed in the working directory folder (pwd / cwd)
{
	"compilerOptions": {
		"allowJs": true,
		"noEmit": true,
		"lib": ["es6"]
	},
	"compileOnSave": false,
	"exclude": [
		"node_modules",
		"typings",
		"*.d.ts",
		"*.ts"
	],
	"typeAcquisition": {
		"enable": false,
		"exclude": [ "node" ]
	}
}

@ArtemAvramenko
Copy link

ArtemAvramenko commented Jul 25, 2018

The problem is reproduced when I open a project from a directory with junction to another drive (mklink /J command). If I create junction from D: to C:, Visual Studio shows me duplicates in same file:

  • C:\MyProject\some.d.ts
  • D:\MyProject\some.d.ts

@alochana9
Copy link

RESOLVED BY BELOW STEPS
I got errors related to d.ts and duplicate identifier errors while deploying my application.
I opened containing Folder - properties - removed read only option in the bottom.
Clicked on Apply and OK.
Restarted visual studio , opened solution , clean,build and published again .
And all errors related d.ts cleared off.
Hope this helps someone.

@3x0dv5
Copy link

3x0dv5 commented May 5, 2019

I found that "untick" the Enable project references helped with "ts2300 duplicate identifier Promise" in visual studio 2019

image

@jurion
Copy link

jurion commented Jul 10, 2019

Resolved for me as well using this tsconfig :
{
"typeAcquisition": {
"enable": false,
"exclude": ["node"]
},
"compilerOptions": {
},
"files": [

]

}

Visual Studio 2019.

@RyanCavanaugh RyanCavanaugh removed their assignment Jul 15, 2019
@RyanCavanaugh
Copy link
Member

Closing - please log a fresh bug with concrete repro steps if you encounter this unexpectedly. Thanks!

@Eli-Black-Work
Copy link

I was able to reproduce this with VS2022, so I've created a fresh bug with a minimal repro and steps to reproduce: #36294 🙂

The root cause seems to be using Yarn 2 or Yarn 3 with a project that has workspaces, as Yarn 2/3 creates hardlinks for the projects in the workspace, and this throws TS for a loop.

Thanks to @ArtemAvramenko's comment (#14565 (comment)) for pointing me in the right direction! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.