TypeScript Version: 2.0.2
Code
tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"target": "es5",
"module": "amd",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"outDir": "wwwroot/js"
},
"include": [
"./TypeScripts/**/*.ts"
],
"exclude": [
"node_modules",
"Typings",
"wwwroot"
]
}
In VS 2015 update 3 with TypeScript 2.0.2 tooling installed i'm facing an issue. I can't exclude my node_modules folder. When i start build my project it raises errors inside *.d.ts files which needed to be excluded.
In VS 2015 only TypeScript 2.0.2 tooling installed.
Command 'tsc -v' shows version 2.0.2.
Command 'tsc --project tsconfig.json' don't show any output.
Command 'dotnet build', 'dotnet run' don't produce any issue.
I'm having asp.net mvc core project with angular2.
Please help.
File structure:
wwwroot\node_modules - NOT EXCLUDED
wwwroot\Typings - OK
wwwroot\TypeScripts - OK
...
...
Typings - OK
node_modules - OK
...
Expected behavior:
Avoid and exclude wwwroot/node_modules ts files.
Actual behavior:
It tries to check ts files in the folder wwwroot/node_modules.
Workaround:
The workaround of this situation to remove wwwroot/node_modules folder. Start project in VS. Recreate wwwroot/node_modules folder with all files. Now everthing works even if rebuild project.
But if a restart VS then i will face the same behaviour.
Typescript 2 looks for declaration files in node_modules
folder regardless of exclusion when --moduleResolution
is set to node
, you can see which files are checked with the --traceResolution
option. One or more files there use implicit any
which you have disabled in your configuration, one way to get around this for now is to use the --skipDefaultLibCheck
or --skipLibCheck
option in which case, you'd be losing some of the guarantees of TypeScript.
Do you have an import for this file, or a triple slash reference? see https://github.com/Microsoft/TypeScript/wiki/FAQ#why-is-a-file-in-the-exclude-list-still-picked-up-by-the-compiler
@bondz folowing your logic if i remove *.d.ts files in my 'wwwrootnode_modules' folder i should be fine.
and i did to try, but seems it didn't work. When I compile with removed declaration files, it still compiles *.ts files in the folder 'wwwrootnode_modules' because it starts raising errors in declaration files but now inside 'node_modules' folder which is located in my root folder.
Considering what wrote @mhegazy and what is written in the documentaion of how module resolution performs when I chose 'node' type it kinda makes logic for me.
What I see from my perspective that 'node_modules' which in the root folder is excluded fine. But 'wwwrootnode_modules' isn't excluded at all.
if i try to run:
'tsc wwwrootnode_modules...\foo.d.ts' - it raises erros.
'tsc node_modules...\foo.d.ts' - it raises erros.
'tsc --project tsconfig.json' - shows no erros.
if open my Visual Studio files:
'wwwrootnode_modules...\foo.d.ts' - raises errors in my IDE.
'node_modules...\foo.d.ts' - shows no errors. how?
All errors related to interfaces like 'map', 'promise', 'set'. which normally should be resolved by using es6-shim declaration files. But in my case i want VS to just ignore them. :\
Just tried --skipDefaultLibCheck and --skipLibCheck and it didn't work. :\
Oh, sorry, but I can't seem to reproduce the error in VSCode. Maybe if you can upload a sample?
@bondz this issue only impacts Visual Studio. I'll try to upload to github and let you know.
I just added my rep on github - https://github.com/szykov/WebServicesApp
After that you may try to compile in Visual Studio.
I'm having the exact same problem with my own repo since I updated to 2.0. I can compile fine from the commandline with tsc, but when I use Visual Studio, it parses the whole node_modules folders and start failing the compilation.
The workaround he proposes works. But what a pain...
I can repro with 2.0.3
@jsgoupil well written.
I can also confirm that upgrading typescript from 2.0.2 to 2.0.3 version didn't solve the issue and on typescript 1.8.6 i didn't have such issue. For some folks downgrading back to 1.8.6 would be a workaround also but not for me due that Angular 2 requires to have typesript 2 version.
@szykov, i am building this project just fine, I would appreciate the help figuring out what is going on. a few questions, if you run tsc as C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.0\tsc.exe --project "c:\test\11055\WebServiceApp\src\WebServicesApp\tsconfig.json"
do you see the same errors? if not can you share a build log with /verbosity: diagnostic
? if yes can you share the errors?
@jsgoupil good to hear from you again, has been a while :).
Do you have a project i can look at?
@mhegazy seems it's always hard to repeat the error :) can you confirm that you used gulp task run copy-npm? When i run tsc.exe --project "tsconfig.json" - i'm fine. It produces no errors.
I attached files. Thanks.
@mhegazy My project is a little too big right now and I'm going on vacation. I took @szykov project and tried it and I can repro.
cd WebServiceApp\src\WebServicesApp
npm install
..\..\WebServicesApp.sln
CTRL+F5
// Success.
Close Visual Studio
gulp copy-npm
..\..\WebServicesApp.sln
CTRL+F5
// Fail
I see the same thing, I have a minimal repo which I try to exclude spec files and they still get compiled running tsc.
Exclude is misspelled : https://github.com/beckend/typescript-project-exclude/blob/bbc575c71030120aabf9b380222814bf5c9be74e/tsconfig.json#L20
Fix it and alm doesn't include the excluded files :
Despite what @basarat mentions, this bug is still happening to me. What @backend mentions is not related to this bug.
Please see my repro higher.
I believe @beckend's issue is off-topic here.
thanks @szykov for the repro. i managed to diagnose the issue. The problem is the MSBuild targets crawls the project directory to find any tsconfig.json
file to build. and in this case it picked up tsconfig.json
files under wwwroot\node_modules\*
which obviously is not correct. I have a fix for this in our internal repo, and should be released within the two weeks.
As a workaround for now, you can list the tsconfig.json files in your project explicitly, so unload your project, and add the following before the import to $(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets
:
<ItemGroup>
<Content Include="tsconfig.json" />
<Content Include="wwwroot\lib\moment\typing-tests\tsconfig.json" />
</ItemGroup>
@jsgoupil your file names obviously would be different, but you need to list all the tsconfig.json files you need built from this project.
@mhegazy thank god, you fixed this. My life was so unfortunate and painful with all these repeating 'node_modules' removing actions. And now it's getting better, I even started smiling.
Thanks. Keep up the good work.
I found that some node_modules subfolders contains tsconfig.json. Maybe problem can be there
Visual Studio support of Typescript 2 is a big mess :(.
@mayerwin sorry to hear you are running into problems. have you been using TypeScript 2.0.6? can you share more information about the issues you are running into?
@mhegazy Yes, I am using TypeScript Tools 2.0.6. I had to downgrade my project to targeting 1.8 (which was still installed by default with VS 2015) as everything broke when trying 2.0. Not the same experience as when upgrading a project's target .NET framework :(. I have been too spoiled by the .NET developer experience and thought TypeScript and TypeScript support in Visual Studio was already on par. One frustrating issue I encountered for example is having the project compile but the Error window still report hundreds of errors. Part of my rant definitely has to do with how immature/fragmented/incompatible the whole Javascript/Typescript ecosystem is compared to .NET, which is just the way it is, not Visual Studio's fault (though maybe Microsoft should push for a more opinionated way to handle TypeScript/npm/etc.).
So, TLDR: keep up the good work, at least I am confident this is in good hand!
Additional information on what errors you ran into would be appreciated.
Where can i find the definition of react-select-props
?
They are part of the react-select typings: typings install dt~react-select --global --save
.
Also here (not sure if this source corresponds to TypeScript 1.8 though): https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/react-select/react-select.d.ts
I still do not see the issue..
c:\test\sandbox3>type typings.json
{
"globalDependencies": {
"react": "registry:dt/react#0.14.0+20161008064207",
"react-select": "registry:dt/react-select#1.0.0+20160927230349"
}
}
c:\test\sandbox3>type a.ts
import { Option } from "react-select-props";
declare var Option: { new (text?: string, value?: string, defaultSelected?: boolean, selected?: boolean): HTMLOptionElement; };
c:\test\sandbox3>tsc --listFiles
C:/Users/mhegazy/AppData/Roaming/npm/node_modules/typescript/lib/lib.d.ts
c:/test/sandbox3/a.ts
c:/test/sandbox3/typings/globals/react-select/index.d.ts
c:/test/sandbox3/typings/globals/react/index.d.ts
c:/test/sandbox3/typings/index.d.ts
c:\test\sandbox3>echo %ERRORLEVEL%
0
The issue was not with TypeScript itselfs which compiles fine but with Visual Studio Intellisense. Actually after checking further it seems to be due to the typings only exposing an interface for the Option
object, not the constructor (even if the constructor seems to exist in Javascript). So when trying to create the object with the new Option(label, value)
constructor, Intellisense was probably not finding the corresponding declaration and the only thing it could suggest was the constructor for the Option
HTML object.
@mhegazy I believe this bug resurfaced in VS2017 RC.
It's probably worse actually. I cannot build at all with this /wwwroot/node_modules present... It's not being ignored. So every time I build, I have to remove it from the hard drive. VS2017 keeps a lock on folders as well. So I have to restart VS2017 every time I want to build... completely unusable.
I have this in my csproj <Compile Include="**\*.cs" Exclude="node_modules\**\*.cs;wwwroot\node_modules\**;bin\**;obj\**;**\*.xproj;packages\**">
and this in my tsconfig:
"exclude": [
"wwwroot",
"node_modules"
],
@jsgoupil - i was having the same problem
i'm guessing that visual studio is running tsc with the ts files as command args so the tsconfig is ignored?
anyway, from VS 2017 RC, i right click node_modules
folder and exclude from project and the ts build errors go away :smile:
this is what it added to my csproj:
Note: I created my angular2 project using the cli in the project folder, this creates the angular2 project folder (i called mine spa
) in the project folder (not the wwwroot
folder). so my node_modules
folder is under spa
. then i edited the angular-cli.json
file, changing "outDir": "../wwwroot"
(was "outDir": "dist"
). then ng build
deposits the webpack bundled app into wwwroot
I had issue with Internet Explorer and when I change tsconfig.json flag 'target' from 'es6' to 'es5', then the app is running smoothly in IE and Nitro, Maxthon etc. browsers. But problem arose for 'tsc' compilation, which started compiling 'node_modules' folder, while it is excluded in tsconfig.json.
Adding the following flag, in tsconfig.json resolved the issue of not respecting 'exclude' flag of tsconfig.json by 'tsc'.
"lib": [ "es6", "dom" ],
Yeah, still an issue in Visual Studio 2017. @jsgoupil I'm having the same issue, and haven't found a way around it.
@justinhp I definitely went back to VS2015. If this is blocking you should probably open a bug because this one is closed. Microsoft guys won't be looking at it.
For future questions and if wondering why this mistakes are happening on compilation it is because there is discrepancies between all these modules and your aim that you told TypeScript
compiler, so if I were you I will change tsconfig to ES6 from ES5 and update my modules with npm i moduleX@latest --save (--only=dev)
in tsconfig in my case running systemjs I have simple approach
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
Also I will trim some of my unnecessary packages that includes typings and unclear dependencies, if you are curious which module is the problematic you can make an experiment remove/delete node_modules folder
and add start installing them one by one and after each installation compile by calling tsc
and you will which one is the bad one, it takes the most 5 minutes.
Once fixed it will work even in VS 17.
I use VS Code but tested in studio as well and it is fine there.
My problem was that I included a file in one of the excluded folders.
Thank you @mhegazy 馃槂
This is still an issue in visual studio 2017, why is it closed?
in project tsconfig.json there is:
"exclude": [
"*/wwwroot/lib/" // Don't operate on lib directory to prevent warnings from lib code
]
and yet I get errors from a mobiscroll under /wwwroot/lib/mobiscroll/src/forms.angular.ts
where my javascript code only imported mobiscroll/bundles/mobiscroll.jquery.js which does not import the angular typescript files.
None of the written solutions worked. compiling project tsconfig from command line with tsc does not throw errors. So I guess the problem is that visual studio reads tsconfig in an excluded directory, which was supposed to be fixed as said in comments above by @mhegazy but seems it is NOT fixed.
Update: found a working solution: disabled typescript visual studio extensions and restarted visual studio.
I do not use TypeScript on all projects, and have to disable and enable it every time i switch them.
I think this should be fixed, immediately.
Excluding "*/.ts" doesn't even work.
This issue is closed over a year ago. if you are running into problems, please log a new issue and provide enough context for us to reproduce it. commenting on a year-old issue helps no one.
Most helpful comment
Typescript 2 looks for declaration files in
node_modules
folder regardless of exclusion when--moduleResolution
is set tonode
, you can see which files are checked with the--traceResolution
option. One or more files there useimplicit any
which you have disabled in your configuration, one way to get around this for now is to use the--skipDefaultLibCheck
or--skipLibCheck
option in which case, you'd be losing some of the guarantees of TypeScript.