-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Comments
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. 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. 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:
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\Microsoft\TypeScript\node_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! |
The same problem. Just opened solution which worked fine on VS2015 with new VS2017 - can't build, errors: |
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! |
@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": { 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:
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 |
@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: #14565 (comment) I just set it like this: "typeAcquisition": {"enable": false} |
Fix available; PR pending soon There are actually two issues here:
|
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). 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 |
@billti: removing nugetted typings breaks TFS build running on buildserver ! |
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.
|
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 |
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 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 I received this error after I did the following:
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 |
Resolved for me as well using this tsconfig :
} Visual Studio 2019. |
Closing - please log a fresh bug with concrete repro steps if you encounter this unexpectedly. Thanks! |
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! 🙂 |
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:
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:
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:
The text was updated successfully, but these errors were encountered: