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.
Type definitions are installed via nuget to default folder: project root/scripts/typings/
For build I use nuget package Microsoft.TypeScript.MSBuild" version="2.2.1
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\MicrosoftTypeScriptnode_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:
Can you share your project file? or steps to reproduce this behavior?
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:
Also I will try to create project from scratch with similar settings and check if this issue exist.
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.
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.
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/...
I am also can replicate this issue from scratch:
Also if I am manually delete typings from folder: "~\AppData\Local\MicrosoftTypeScriptnode_modules@types\" errors disappear after several seconds, but when reopen VS this folder populated again causing this errors to appear again.
Same problem has existed with VS2017 since RC. It would be good to a) understand it, b) make it go away!
Steps to reproduce:
Same problem with WebForms project.
Another error: Duplicate string index signature
"
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
I have same problem as indicated by @LbISS. This also include Error TS2300 Duplicate identifier 'ng'.
Also triggered by cleaning and rebuilding the solution.
@mhegazy Thanks for the quick fix!
Is there a workaround while we are waiting for the fix to be released?
@mhegazy Could you please clarify that this fix will be available with Visual Studio 2017 Update 1?
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.
I upgraded to 15.1 (26403.0) today and I still get the errors...
Still happens in 26403.3 as well.
Quick and dirty hack to get around this while waiting for a proper fix:
%localappdata%\Microsoft\TypeScript\package.json
.{
//"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"
//}
}
%localappdata%\Microsoft\TypeScript\package.json
read-only.%localappdata%\Microsoft\TypeScript\node_modules\@types
After a VS restart, clean, rebuild everything is back to normal (for me at least).
@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...
@odrozd sorry, forgot to mention to make %localappdata%\Microsoft\TypeScript\package.json
read-only
@jjoekoullas you make my day)) I'll try it asap
It seems these are not solutions but work arounds and hacks. I found that turning off the Type Script compiler in the VS Solution files is good also but Microsoft should be fixing this issue to be honest.
Here is a link for you to maul over:
Typescript compiler disabled-> https://github.com/Microsoft/TypeScript/issues/2294
Though improved, still happens in 26403.7 after re-compile.
the same, still errors exists
Guys, I am pretty sure that they will address this issue in scope of update typescript plugin for VS 2017, current plugin support only TypeScript 2.1 and they work to bring new version here
Anyway it would be great to get confirmation or other update regarding current issue state from TS team members.
The latest VS Preview (https://www.visualstudio.com/en-us/news/releasenotes/vs2017-Preview-relnotes#15.2.26412.01) includes SxS support for TypeScript versions, and should fix most of the above issues also. By end of week (or early next week) the Preview will be updated again to (hopefully) address all the issues outlined above.
There were a couple of factors impacting VS here. One was the issue @mhegazy fixed above around semantic errors in JS files, and another just recently discovered that @zhengbli fixed with #15080 where the project structure was getting confused. Apologies for the pain & frustration these have caused.
Even with the preview, I still get those errors.
I have found adding a typescript config file to the root of my project fixes Duplicate Identifiers found in the nuget jquery typings and the typings that is buried somewhere in my home folder.
If you can share a repro @AndreR we can look into it. Do you have TypeScript source files in your project, or just JavaScript?
@billti Unfortunately it's an internal project, so I can't share it unfortunately. I get exactly 684 errors, all duplicate identifiers. The errors appear in various places, mostly the d.ts files. For example:
There is also this strange thing, that it tries to access C:/MyProjectFolder/packages/globalize.TypeScript.DefinitelyTyped.0.3.1/Content/Scripts/typings/cldr.js/cldr.js.d.ts, which doesn't even exist. I don't know, why it tries to load it.
I have a tsconfig.json in my root folder:
{
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": true,
"noEmitOnError": true,
"removeComments": true,
"sourceMap": true,
"target": "es2015"
},
"exclude": [
"node_modules",
"wwwroot"
]
}
PS:
Looks like I found the reason for this strange behavior: It tries to load the typings from the Scripts/typings folder as well as from the packages folder, since I've updated my Visual Studio to update 1.
After excluding the packages folder through the tsconfig.js, I could significantly reduce the error message. Now I get a "namespace 'cldr' couldn't be found" from the globalize.d.ts, though. I guess, that this has something to do with that "file not found" error from above, which is still present.
Thanks for the info @AndreR . It sounds like possibly a different issue than those above, which were largely due to errors from JavaScript files or projects getting recalculated randomly - both of which should be fixed in the preview.
What added the "packages" folder to your project? Is this a NuGet install location?
Are you seeing the same errors from build on the command line? If so, you could try the --traceResolution
flag to see if that shows you what is sucking in the unexpected file.
If this still look like a bug in TypeScript, could you open a new issue for it with a summary of the info to date? Thanks.
@billti I can't reproduce the error right now. I somehow must have found a workaround for it, but I can't tell you exactly what I did.
The packages folder was indeed added by NuGet. Unfortunately, I haven't checked the command line build back then.
If this error should appear again, I will tell you.
This happened after doing a web deploy. Seemed the language service was including some of the temporary deployment code in the obj\ directory (specifically, "obj\Release\net461\win7-x86PubTmp\Out\wwwroot").
Just want to note that doing a clean does not seem to clean these temporary files.
nh43de
This happenes during build too. I'm developing core mvc app keeping some scripts in Views directory, and they are copied to output directory (with corresponding property being set) after build. So they stay in Debug and Release directories.
This problem can be solved by setting output in project settings outside project directory or by calling rmdir command after build event. But not publishing problem, which includes ts files in any directory. PubTmp creates after rmdir and it is always in obj\ .
Laguage service is scanning whole project folder for .ts files. It should ignore output folders for each configuration and "obj" folder. Or it should scan only ProjectItems in IDE, ignoring files that are not included in project tree.
Today I had the same problem. Solution: Updating VS to 15.2 (26430.6)
deanpodgornik
I have the save version. And i have found solution for PubTmp: https://github.com/dotnet/sdk/issues/980
Same, solved to VS to 15.2 (26430.6) solved my problem
Still typescript Errors Version 15.2 (26430.12) visual studio 2017
Duplicate identifiers
I still get this issue after updating to 15.2.
In ASP.NET Web Application projects I'm able to avoid this issue by downgrading the project TypeScript version from 2.2 to 2.1, however in Website projects (that don't use a .csproj
file, but use .sln
directly) there is no way to specify a TypeScript version so I cannot work-around this issue.
can you share a project or some repro steps?
I resolved this issue following below steps,
Please look for TypeScriptCompileBlocked being defined as FALSE inside of the
IF it's defined as false, go back to .csproj file and add the following section,
<PropertyGroup>
<TypeScriptCompileBlocked>True</TypeScriptCompileBlocked>
<PropertyGroup>
Build the project again.
@Manojb86 Doesn't that mean that Visual Studio won't compile your TS files?
At least thats what the docs seem to say.
@mhegazy Please reopen this issue, it is still a problem.
I acquired this problem today after upgrading to VS2017 15.3 Preview 3.
Yes, the problem definitely still occurs in the most recent versions.
@AndreR - your prior update on this issue stated:
I can't reproduce the error right now. I somehow must have found a workaround for it, but I can't tell you exactly what I did
So did this recur for you? Is it still intermittent, or do you have a consistent repro? Do you have something you can share with us to try and recreate? (Same questions to you @geirsagberg ).
Are you seeing these errors in TypeScript or JavaScript files? What version of TypeScript is being used (this is configurable in Tools / Options)?
Unfortunately there is a large number of possible configurations and settings, and this is also a perfectly legitimate and valid error in many projects which can be hard to troubleshoot. Without detailed info and preferably a repro, this is going to be hard to figure out. If it is occurring when it shouldn't, then it must be something quite specific to your setup (I'm using 15.3 daily, and I've never seen it when it wasn't a valid error).
I had the same problem. Here is what I've fixed it with:
First, I've removed compiled .js and .js.map files from the project.
Then, I've installed TS 2.5 SDK, and set "
After reloading the project, I didn't have the error ever again.
I'm not sure which step solved the issue, but I believe it may be helpful to somebody.
I'm still experiencing this too, I thought the @Andrey-Anatolyevich solution fixed it for a bit, but then it came back again. Also tried the @jjoekoullas fix, but that didn't help.
I'm getting either 181 or 362 errors, mostly "duplicate identifier" errors from index.d.ts and jquery.d.ts, plus a few other library typings; and a handful of other error types as well.
I'm using VS 2017 15.3.3, TS 2.5, and have updated all my typings to the latest versions.
The errors disappear when I restart VS (cleaning the solution does nothing), not sure what triggers their reappearance, but it doesn't appear to have anything to do with building or debugging the app, nor saving any changes to a TS file to trigger a recompilation; the errors just show up after about 5-10 mins (even if I open the solution and just leave it sitting there, doing absolutely nothing).
@david-grogan can you report this issue through "Report a problem" tool, this will allow us to capture some additional information to be able to debug the issue.
Also CC @billti and @amcasey
done.
After installing VS 2017 15.3.4 this issue seems to have gone away.
I spoke too soon, after using it for three days without the errors appearing they just came back again.
¯_(ツ)_/¯
Still having the same issues with VS2017 15.4.1
I installed 15.4 recently and the issue was still happening, but then I tried the workaround described here again: https://github.com/Microsoft/TypeScript/issues/14565#issuecomment-293597871
...and this time it worked.
I am now on 15.4.1, and the workaround is still in use and still working.
One thing I noticed before was that the errors wouldn't appear if I loaded up a solution where the active file was a C# file, if I just worked on that code and other C# files the error wouldn't appear, and sometimes even after a while I could open up a .TS file and the errors wouldn't reappear (though they usually did, wasn't able to discern a pattern there). This was why I thought the error had disappeared in my Sep 20th post, I had gone several days without seeing the errors. What was a guarantee though was opening up a solution where the active file was a .TS file would cause the errors to appear after a few mins.
@jeroenlandheer and @david-grogan can you share a repro project?
Are those affected all NOT using tsconfig.json (i.e. all your TypeScript settings are in the MSBuild properties in the VS project file)? I have noticed that on occassion the project context we create for such project (which we call "external" projects), will automatically also include all the type definitions under the types cache location (which the workaround linked to effectively disables).
If you could confirm (and even better, if you switch to using a tsconfig.json does the issue go away), that would be very helpful.
I got the problem with or without a .tsconfig (generally I don't use one).
@mhegazy I can't share the project I'm working on, and don't really have too much time to try and create a new repro project.
@david-grogan Sorry, but this is an internal project, I can't share it.
Some packages that cause this:
Hope this helps
@mhegazy do you want me to send you my project(in private)?
@jeroenlandheer So you do have two copies of each .d.ts in the project? One from NuGet and one in scripts/typings? Is there a reason you need both included?
For me it helped to select the project in the Solution Explorer, then go to the menu option PROJECT and click "Convert to Web Application".
@billti If you install a nuget package, you get 2 copies. One is in the "packages" folder of your solution where the nuget package is extracted, the other is in the "Scripts/typings" directory of your web project.
I'm using now npm to get around this and use tsconfig & gulp to compile my typescript. I've disabled typescript compiler in the project. It is a bit convoluted but it works.
I was getting this error when using dojo-typings installed via npm. Because these don't installed into the @types folder I referenced them manually in the "Include" of tsconfig. For some reason this causes all of the duplicate errors.
Instead I went back to my old way of creating a tsc.d.ts in the project root which includes the references:
tsc.d.ts
/// <reference path="node_modules/dojo-typings/dojo/1.11/dojo.d.ts" />
/// <reference path="node_modules/dojo-typings/dojo/1.11/modules.d.ts" />
/// <reference path="node_modules/dojo-typings/dojox/1.11/dojox.d.ts" />
/// <reference path="node_modules/dojo-typings/dijit/1.11/dijit.d.ts" />
/// <reference path="node_modules/dojo-typings/dojox/1.11/modules.d.ts" />
Still reproduced in 15.4.4 when jasmine.d.ts is installed.
Reproduced with 15.4.4 and knockout (npm install --save @types/knockout
) with TS 2.3 and TS 2.6.1
Why is this bug closed btw?
What works for me was deleting the folder
C:Users[Username]\AppData\Local\MicrosoftTypeScript
Don't know if this has side effects - currently it seems to work
Edit: After a reboot the folder was recreated - so it only temporary helped.
@mhegazy @billti I create a project with which the bug can be reproduced. How can I send it to you?
It is not fixed, please reopen the bug
@ManuelHaas If you can send it to billti at microsoft dot com, then I'll take a look.
Reopening while investigating....
@billti you have mail ;)
Thanks @ManuelHaas . I got the project and can see the problem.
In your case it's because the knockout definitions are indeed included twice. Here's why.
In your solution folder (one up from the project) you have a node_modules
folder containing the @types\knockout
package. So when your project opens and the TypeScript project is created, and it sees the import * as ko from "knockout";
in the source file, it walks up looking for a node_modules\@types\knockout
folder, sees this, and includes the knockout definitions.
However in the tsconfig.json
for your project you also have "typeAcquisition": {"enable": true}
, which means it will go fetch the type definitions for the libraries it detects in use and include them. It sees knockout being used, so it goes fetches the knockout library into the cache. Thus, two distinct copies of the knockout definitions are included, leading to duplicate...
errors.
There are a few ways you can fix this:
@types\knockout
NPM package you have in your solution - but I'm guessing the TypeScript project uses this."typeAcquisition"
settings, add the entry "exclude": ["knockout"]
- this way it won't go automatically acquire this package again.Arguably we should also not go fetch & include a type definition for a package we already are including from under one of the type root (CC @RyanCavanaugh ).
Arguably we should also not go fetch & include a type definition for a package we already are including from under one of the type root
Agreed. The code already should work this way - only ATA knockout
when it shows up in the unresolvedImports
list; but knockout
was resolved so it shouldn't be in that list. I'll debug and figure out why that's happening.
@billti: Excluding knockout from typeAcquisition worked for me. Thanks a lot!
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.
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=".
To disable typeAcquisition see @billti's comment above: https://github.com/Microsoft/TypeScript/issues/14565#issuecomment-348328648
I just set it like this:
```json
"typeAcquisition": {"enable": false}
Fix available; PR pending soon
There are actually two issues here:
knockout
to be an unresolved module during cached program rebuilds. PR up soonnode
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 #20402But 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?
You should remove the jquery type definition from under your scripts/typings
folder if it already comes via the NuGet package.
@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...
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?
It is necessary tu run npm -D --save --save-dev _package@name_ for each offending typing file.
Tricks:
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.
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.
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 ?
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.
jquery typings were installed using NPM, i didn't user NuGet for this.
@shelland can u share your project or a sample showing the same behavior?
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.
For me I encountered multiple Duplicate identifier "DataTransfer"
error messages, emitted from lib.d.ts
.
I received this error after I did the following:
babel-eslint
eslint
eslint-config-defaults
eslint-plugin-import
eslint-plugin-react
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" ]
}
}
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:
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.
I found that "untick" the Enable project references helped with "ts2300 duplicate identifier Promise" in visual studio 2019
Resolved for me as well using this tsconfig :
{
"typeAcquisition": {
"enable": false,
"exclude": ["node"]
},
"compilerOptions": {
},
"files": [
]
}
Visual Studio 2019.
Closing - please log a fresh bug with concrete repro steps if you encounter this unexpectedly. Thanks!
Most helpful comment
I upgraded to 15.1 (26403.0) today and I still get the errors...