Typescript: TS2304 Errors appear for excluded files in Visual Studio 2017

Created on 10 May 2017  ·  43Comments  ·  Source: microsoft/TypeScript

Hi,
Premise: I looked carefully for existing issues but didn't find a working answer (although I found many speaking about the same topic).

I am working with Visual Studio 2017, on an ASP.NET MVC Core application where the front end will be implemented using React, ES6 and Babel. No TypeScript.
I have a node_modules folder, hidden in FS and excluded from project, which contains some source .ts files from an external library (react-router).

When I open the solution, after few minutes 4 errors appear as compilation error (TS2304 Cannot find name 'object')

Error

What I tried to do:

  1. Add following configuration to inside .csproj file + Close and Reopen solution
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
  1. Disable JavaScript/TypeScript new service + Close and Reopen solution
    Disabled service

But this wasn't sufficient. To resolve, I needed to disable the TypeScript extension completely from VS and close every instance of VS 2017.

  1. Disable TypeScript extension
    Disabled TypeScript extension

Which in turn removed completely the "JavaScript/TypeScript" entry from Options / Text Editor settings.

Expected behavior:
TS2304 Errors should not appear for files that are not included in the project. In the same way as C# files that are not included in the project (or are not set to "Compile" build action) do not affect compilation (for example). This should not require any special action.

Actual behavior:
Behavior of TypeScript files is inconsistent with other programming languages used in VS. Compilation errors such as TS2304 are appearing also for files that are excluded from project and even hidden in file system.


Kind Regards,
Roberto

Bug Fix Available Fixed Visual Studio

Most helpful comment

Awaiting solution to this issue.

All 43 comments

Are you seeing this on 15.2?

Hi @mhegazy, thanks for answering. No, I didn't update today my VS - I will update tomorrow at work and let you know.

Hello again, @mhegazy. After updating to latest version 15.2, the issue I described went away. Thank You!

Please reopen this issue.
This issue still occurs for me in visual studio 15.3 with following excludes I still get errors from ts files from a subdirectory of lib:
"**/wwwroot/lib/*", // Don't operate on lib directory to prevent warnings from lib code "wwwroot/lib/*", // Don't operate on lib directory to prevent warnings from lib code "wwwroot/lib", // Don't operate on lib directory to prevent warnings from lib code "wwwroot/lib/**", // Don't operate on lib directory to prevent warnings from lib code "**/wwwroot/lib/**", // Don't operate on lib directory to prevent warnings from lib code "wwwroot/lib/" // Don't operate on lib directory to prevent warnings from lib code
image

Hi,
I am reopening the issue because of two reasons:

  • others are saying this exact problem came back with VS 15.3
  • since a few weeks, Visual Studio became really slow when compiling of a solution which contains a node_modules folder (the same project I was referring to when first opening this issue)

Note that I have TypeScript extensions completely disabled; the node_modules folder is hidden in the file system and excluded from the project. Nevertheless, the compilation is impacted by the presence of this folder. The situation is even worse than it used to be, since even having TypeScript extensions disabled doesn't help. I understand this is not exactly the same problem, but I think it may be related.

//cc @billti, @amcasey

I have VS 2017 v15.4.5 and have this problem as well. Since my project uses Typescript heavily, this is blocking my ability to upgrade to VS2017 at all.

anyone had any luck with this?

Not really. I have worked around this by deleting the node_modules/@types directory, and then the errors go away. But I have to do this frequently, because npm recreates the folder. This works but it's very annoying.

My recommendation is to keep your client side ES6/TypeScript source code in a completely different folder than the one used by your server side code and Visual Studio, and configure the build tasks to deploy client side build artifacts into the wwwroot folder of the ASP.NET Core application. I did this in the last web application I am working on. It's annoying but it solves the problem with VS.

Same issue has start form me after I have update Visual Studio 2017 to 15.5.0, versions 15.5.1 and 15.5.2 does not solve this, I have installed Typescript 2.6.2 for Visual Studio 2017. Typescript is compiling *.config files, so there are thousand of typescript errors.

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

I found that if I select build only messages in error list, typescript errors disappear, so it seem to be issue with intellisense

I have this same issue as well, however in a slightly different manner.
We have our entity framework dbcontext classes saved as .edm files and mapped to visual c# in the text editor file extension options. Even adding an exclusion to our .tsconfig does not stop intellisense from trying to throw ts2304 errors on these.

If I remove the mapping then the errors go away.

We are on VS 2017 15.5.5 and typescript 2.6.1

image

image

@mcnallys can you clarify more on how to reproduce this? This is what I see (note that these are correctly C# errors);
image

I'm getting thousands of these for an Asp.net webforms project. No typescript, tsconfig.json, or packages.json, but there is a leftover node_modules folder that isnt part of the project. Happens sporadically. If someone from MSFT wants the feedback collect it should be up on devcomm, but I literally cant help you find it.

image

and clicking on it...
image

Tried everything and can't get rid of these errors. Any suggestions?
They are caused in our project by a third party javascript folder which has typescript files and its own tsconfig file.
Tried add exclusions and tried to disable typescript compilation, nothing helps.

As I wrote before, in the error list choose build only as workaround.
image

Unfortunately this is not a possible workaround for us because we want to use the intellisense for other things.

@guylando, the way I approached this problem in last applications, is to separate completely the folder containing the projects used by Visual Studio and the folder containing the front end source code; then I configured my JavaScript boilerplate to publish artifacts into the folder used by ASP.NET Core (wwwroot).

To develop the front end, we use Visual Studio Code, which in my opinion works much better than Visual Studio IDE for client side development.

Something like:

ProjRepository\
   \aspnet  # for server side code
   \spa     # for single page application, contains node_modules and all client source code

This also makes more sense if you are using official React or Vue.js project templates (and similar) including a Node.js development server - this is usually the case when using WebPack boilerplate.

In my case the presence of node_modules was slowing down the compilation of C# code _(Why ??)_, even though I am working with a pretty good laptop. :sweat:

Hi there, I have the same issue with TypeScript code analysis raising thousands of errors from non typescript nor javascript files on a project that contains no JS nor TS files.

It seams that this occurs after adding an extension on file extension (with a SQL editor in that case) with any "Non TypeScript" editor, TS editor analysis is done. As long as this is NOT Typescript nor javascript, it is normal that it does not comply to TS standard and syntax... but why is it analysed?

Edit : this behaviour is found on latest VS 2017 (15.6.6).
After adding or removing a file extension, analysis errors are append or removed only after a VS restart.

Thanks for the extra info. Can you expand on what you mean by "It seams that this occurs after adding an extension on file extension (with a SQL editor in that case) with any "Non TypeScript" editor, TS editor analysis is done"? I'm not sure I understand exactly.

If you have some repro steps I can try to follow on my test machine (i.e. "Do x, then y,... Now you will see the issue"), I'd definitely love to get this fixed.

@billti create a subfolder named "lib" in the visual studio project and add there a folder named "yyy" placing there a library which uses typescript and has tsconfig of its own such as mobiscroll (https://github.com/acidb/mobiscroll/archive/v4.1.0.zip).
then visual studio intellicense recognizes that folder as a seperate project and does not apply the main project configs of disabling the errors on that folder and trigger many errors on it.

image

even though in my project tsconfig i have:
"exclude": [
"*/lib/",
"lib"
],
and
"noEmit": true

@billti , I have reproduced the problem "from scratch". here are the steps with VS 2017 Pro:
1 - in file extension : add "sql_" extension and associate it to Transac-SQL editor.
2018-04-13_14h03_20

2 - Create a new solution with a C# class library (i have done both for a .Net framework et .Net standard)
3 - Remove default class file created
4 - Add a new file "whateveryouwant.sql_" to the project and put some valid SQL code inside:

SELECT 1 as DUMB_RESULT FROM DUAL;

5 - now add on typescript file "file1.ts" and put some valid ts code inside:

alert('hello');

6 - check your Error list window (it can take some time for analysis)...
2018-04-13_14h11_40

Here is the solution i created

ClassLibrary2.zip

7 - If you remove sql_ extension from file extensions and restart VS, then all errors are removed.

Hope this will help for fixing issue

@gucourti reproduced locally. Thank you so much for providing this repro - I'm investigating the issue now

@gucourti we have a fix but it's on the Visual Studio side. In the meantime we have a patch you can apply to tsserver.js:

--- "tsserver.js"
+++ "tsserver.js"
@@ -85714,6 +85714,7 @@ var ts;
                 }
             };
             ScriptInfo.prototype.getSnapshot = function () {
+                if (this.scriptKind === 5) return ScriptSnapshot.fromString("");
                 return this.textStorage.getSnapshot();
             };
             ScriptInfo.prototype.ensureRealPath = function () {

@mhegazy If this is being fixed in Visual Studio maybe there could be some kind of indication in Solution Explorer that a file is being excluded.

I'm referring to files in the 'exclude' list in tsconfig.json. If VS were to somehow indicate they are excluded it could help debug the 'opposite' problem for people.

@RyanCavanaugh where do we find this tsserver.js file?

Awaiting solution to this issue.

I set flag to tscofig.json
"compilerOptions": { "skipLibCheck": true }

fine work for me

@RyanCavanaugh - any ETA on when this should be fixed in VS 15? I'm on 15.8.x but have had this happen intermittently (but at a lesser rate now, like ~1x per month. used to be >= 2x per week) since at least 15.3.

edit: that may not sound like its happening frequently, and it isn't for _this_ problem. But it is one of the 100+ little problems that crop up in VS and cripple productivity daily.

@RyanCavanaugh - I've also reported this issue via developer community twice now, the most recent one is here but its been sitting in Triaged status for more than a month. I'm curious to know if that reported issue actually made it to this team or if it is was misdirected.

Sorry @StingyJack - I'm looking at your issue on developer community now.

No need to apologize @minestarks, And thank you.

I tried @gucourti's steps in VS 2017 version 15.9.14 and our internal version of VS 2019 version 16.3 Preview and saw no errors in the error list, so I believe we can say that the fix for the original issue has successfully shipped and that new occurrences are likely due to new bugs.

@amcasey - if you can't tell for sure this is fixed by something specific - and convey that, I need you to reopen the devcomm issue. (Op can weigh in on if he is ok with this being closed)

I get weird problems regularly with the project system and specifically JavaScript and node_module related files. Yesterday it started complaining about a web.config having some element reserved for a machine.config, but the web config it was complaining about was in a subfolder of a selenium-something-something node module. This morning it was trying to copy the files from the root of the C: drive (like pagefile.sys, hibfile, etc) into the project output folder. Two weeks ago TS errors were showing up for me, and the hosted 2019 build agent, but not for other coworkers. These incidents eat up a minimum 30 minutes per instance, because restarting VS doesn't fix it. Sometimes they hang me up until I rewrite sections of code that worked before and that I didn't modify.

So you will have to forgive me for appearing to be difficult, but after logging more than 500 issues about different broken things with VS, and getting satisfactory results for maybe 50-75 of those, I'm not keen on opening a new issue if this happens again. Because it too will stagnate for months before some feigned interest followed by an attempted #please-close. I'm more interested in getting this fixed, and holding an item open for longer will make it more visible than a newly opened issue, and bring some truth to the overall quality metrics.

Hey @StingyJack, I wasn't directly involved in the investigation, but I believe the primary fix was in a closed-source component in roughly the 15.9 timeframe. There may also have been a change in this repo to compensate for bad input from VS. Would you find it helpful to have specific version numbers?

This thread appears to have evolved over the course of a year and some of the issues you describe above sound new and distinct. Are you still seeing the problems described in the portion of the thread before I closed it? If so, which VS and TS versions are you using? If not, I'm inclined to track things using the devcomm issue, since the issues in your most recent comment sound separate. Fair warning: you will most likely be asked for additional context and/or repro steps.

I set flag to tscofig.json
"compilerOptions": { "skipLibCheck": true }

fine work for me

This works for me as a workaround to this issue.

For me this issue is happening on VS code (version below), dotnet.exe (3.0.100), and Visual Studio 16.3 (just updated this week). Slightly different bug version (TS2305 vs. TS2304), though.

Version: 1.38.1 (system setup)
Commit: b37e54c98e1a74ba89e03073e5a3761284e3ffb0
Date: 2019-09-11T13:35:15.005Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 6.3.9600

@amcasey - thanks for the info, sorry for not seeing this until it was commented again. I only want all these weird and intermittent TS/JS behaviors to stop. They have been happening since VS 2017 through 2019.

I haven't had many in the last 2 months or so, but I've been working with python and not using VS much.

@StingyJack all the focus is going on VSCode for what I can tell. I use both at the same time. Took a little used to diffferences in the editors but once I was up to speed it made a lot more sense to me to keep ASP.NET Core stuff in Visual Studio and typescript in VSCode.

MSFT putting any more effort into VSCode other than the initial push and governance seems like a broken business model to me seeing as the program is freely given away and VS collects license money.

On the same token, MSFT putting any features into VSCode that arent put into VS first. or prioritizing non-critical-path feature work for VSCode before bug fixes for VS is flatly the _wrong thing to be doing in regards to their customers that paid for a license for the world's premiere IDE_.

@simeyla - I'm not upset with you suggesting it, since you are also a victim of their unfortunate choices. I've had MSFT staff make suggestions to "just use VS code" instead of fixing a bug in VS before and its carries all the negative emotions that accompany getting ripped off for an amount in the high 4/low 5 digit range (like buying a car that is full of problems and the seller is acting shady).

In my case, I get these and I am not directly using Typescript in any projects. One time VS started freaking out about some of the culture specific js files that were included as part of globalize.js - no TS in any project. Another time it refused to build a solution, pointing out a perfectly fine bit of TS in a project I hadn't touched that it just could not resolve the types for. It also failed to compile on the DevOps hosted build server, but worked fine on every other coworkers PC.

There are a dozen other TS problem instances (all slightly different) that have been work stopping until I recode something that I didn't change in the first place (and would be out of scope for the sprint to do so) or do something drastic like removing files from projects. This has been going on for _years_ now. I would like VS to stop failing to compile due to TS errors when there isnt any TS present, and when I'm not touching anything that would cause any TS to need to compile (we have gated checkin, non-compile-able source cant really get into the codebase).

Totally agree with Andrew.

Regards,
Nagendra

Gift yourself a stress-free life!
Experience Sudarshan Kriya today!!!

On Sun, Sep 29, 2019 at 4:42 PM Andrew Stanton notifications@github.com
wrote:

MSFT putting any more effort into VSCode other than the initial push and
governance seems like a broken business model to me seeing as the program
is freely given away and VS collects license money.

On the same token, MSFT putting any features into VSCode that arent put
into VS first. or prioritizing non-critical-path feature work for VSCode
before bug fixes for VS is flatly the wrong thing to be doing in regards
to their customers that paid for a license for the world's premiere IDE
.

@simeyla https://github.com/simeyla - I'm not upset with you suggesting
it, since you are also a victim of their unfortunate choices. I've had MSFT
staff make suggestions to "just use VS code" instead of fixing a bug in VS
before and its carries all the negative emotions that accompany getting
ripped off for an amount in the high 4/low 5 digit range (like buying a car
that is full of problems and the seller is acting shady).

In my case, I get these and I am not directly using Typescript in any
projects. One time VS started freaking out about some of the culture
specific js files that were included as part of globalize.js - no TS in any
project. Another time it refused to build a solution, pointing out a
perfectly fine bit of TS in a project I hadn't touched that it just could
not resolve the types for. It also failed to compile on the DevOps hosted
build server, but worked fine on every other coworkers PC.

There are a dozen other TS problem instances (all slightly different) that
have been work stopping until I recode something that I didn't change in
the first place (and would be out of scope for the sprint to do so) or do
something drastic like removing files from projects. This has been going on
for years now. I would like VS to stop failing to compile due to TS
errors when there isnt any TS present, and when I'm not touching anything
that would cause any TS to need to compile (we have gated checkin,
non-compile-able source cant really get into the codebase).


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/microsoft/TypeScript/issues/15730?email_source=notifications&email_token=AESI6BDSRO6MCRPTFFSSBSDQMEHLBA5CNFSM4DK3HWH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD736GIA#issuecomment-536339232,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AESI6BFS7U7O5BHVKCQCVV3QMEHLBANCNFSM4DK3HWHQ
.

Was this page helpful?
0 / 5 - 0 ratings