PacktPublishing / ASPdotNET-Core-and-Angular-2

Code Repository for ASP.NET Core and Angular 2, Published by Packt
MIT License
33 stars 17 forks source link

Code won't compile because of some typescript error #1

Closed DaveConsulting closed 8 years ago

DaveConsulting commented 8 years ago

Hi,

The first chapter solution won't compile. The error in the VS 2015 Error List is: Error MSB6006 "tsc.exe" exited with code 1. OpenGameListWebApp_Chapter01 C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets 214

This is shown in more details in the output window: Target "CompileTypeScriptWithTSConfig" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets" from project "C:\Users\dave\Downloads\ASPdotNET-Core-and-Angular-2-master\src\OpenGameListWebApp_Chapter01\OpenGameListWebApp_Chapter01.xproj" (target "Compile" depends on it): 1> Task "VsTsc" 1> C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\tsc.exe --project "C:\Users\dave\Downloads\ASPdotNET-Core-and-Angular-2-master\src\OpenGameListWebApp_Chapter01\tsconfig.json" --listEmittedFiles 1> C:\Users\dave\Downloads\ASPdotNET-Core-and-Angular-2-master\src\OpenGameListWebApp_Chapter01\error TS5023:Build:Unknown compiler option 'listemittedfiles'. 1> 1> 1>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets(214,5): error MSB6006: "tsc.exe" exited with code 1. 1> Done executing task "VsTsc" -- FAILED. 1> 1> 1>Done building target "CompileTypeScriptWithTSConfig" in project "OpenGameListWebApp_Chapter01.xproj" -- FAILED.

I use Visual Studio 2015 with update 3, and .NET Core for Visual Studio Tools Preview 2.0.1. on a Windows 10 PC. My other ASP.NET Core solutions and projects work just fine.

Please help. I can not go further with my book.

Thanks, Dave

wmlockhart commented 8 years ago

This won't fix your issue but it will hopefully provide you with more detail on the issue. Enable detailed output in Visual Studio -> Tools -> Options -> Projects and Solutions -> Build and Run -> MSBuild project build output verbosity. Change this to Detailed. After compiling, find tsc.exe in the output window to see the actual error tsc was throwing.

wmlockhart commented 8 years ago

A further thought: installing / re-installing TypeScript for Visual Studio (to the current version) might solve the issue, even though TypeScript may already be installed globally on your machine via npm. Download here: https://www.microsoft.com/en-us/download/details.aspx?id=48593

Darkseal commented 8 years ago

Hello,

this seems to be a known issue on some VS2015 installations that might have become "broken" due to the frequent updates released lately (Updates, Tooling & more): the problem is that your VS2015 - as you can see in your logs - is now executing TSC with the option switch --listEmittedFiles, which is not supported by MSBuild and also not yet available in TS1.7 (which you're correctly using), thus throwing a blocking error.

That said, you might try the following:

  1. Go to this folder on your PC: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio
  2. You should have a /v14.0/ and a /v15.0/ folder there. Go into v15.0, get into the /TypeScript/ subfolder and look if there's a "listEmittedFiles" option in the various .targets files: you shouldn't be using that option, as you're using TypeScript v1.7.5 and it's not supported there, so I suggest to deactivate it if you find it.

If the above doesn't fix your issue, I can suggest to follow the workaround described in this other GitHub topic to reset your VS+TS environment and try again.

If even this doesn't help you, please let me know the exact version of TypeScript you're using (i.e. 1.7.5): you will see it by typing "tsc" from command prompt, as VS will use the version which is in the PATH (unless being told otherwise, which shouldn't be the case). Please also tell me if you ever installed TypeScript 2.0 on your machine, as it could be the cause (even if you uninstalled it).

EDIT ( @wmlockhart ): thanks for your suggestions regarding this issue. I'm not sure that installing TypeScript 2.0 would fix this, as it could potentially open a whole lot of issues. I will try tonight and let you know about this.

Darkseal commented 8 years ago

Just tried installing TypeScript 2.0 using this link: everything seems good so far. Note the "--listEmittedFiles" option being used in the command-line (no errors, as TS2.0 acknowledges it). It seems like a viable fix to me for the issue experienced by the OP: thanks @wmlockhart !

Target "CompileTypeScriptWithTSConfig" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\TypeScript\Microsoft.TypeScript.targets" from project "D:\DarkAngel\Projects\Packt\Solutions\OpenGameList\src\OpenGameListWebApp_Chapter01\OpenGameListWebApp_Chapter01.xproj" (target "Compile" depends on it): 1> Task "VsTsc" 1> C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.0\tsc.exe --project "D:\DarkAngel\Projects\Packt\Solutions\OpenGameList\src\OpenGameListWebApp_Chapter01\tsconfig.json" --listEmittedFiles 1> Done executing task "VsTsc". 1> Task "AssignTargetPath" 1> Done executing task "AssignTargetPath".

DaveConsulting commented 8 years ago

@wmlockhart and @Darkseal : Thanks a lot for your help. As you both mentioned, it had something to do with previous typescript installation which was probably broken due to many updates of VS.

After installing the latest TypeScript 2.0.6 as @wmlockhart suggested, every thing seems to work fine. I can compile and continue to read and learn from the book.

Thank you guys.

By the way, it is really a great book!

Darkseal commented 8 years ago

I'm very happy you managed to fix your issue and I'm glad you're liking the book so far! 👍 :)

ITSUUUUUH commented 7 years ago

@Darkseal and @wmlockhart I tried completing this project using typescript version 1.8.10 and version 2.0.10 (global install), but i ran into an issue where my project fails to build due to this error: "build: unknown compiler option 'listemittedfiles'" ts2 0 10global_1 8 10_build_error

After doing some research, I was pointed to this ticket. I installed typescript version 2.0.06, and I was able to build my project, but I ran into problems when trying to edit js files in Visual Studio: ts2 0 06_jsfile_error Updating to this version of typescript also removes syntax highlighting and intellisense when working with ts files: ts2 0 06_tsfile

There is a ticket still open on the typescript GitHub page that addresses this issue, but does not resolve it: https://github.com/Microsoft/TypeScript/issues/10608


In short, while the above fix for this ticket may make the project usable, it is not a sensible solution as all js files need to be edited outside of visual studio.

Darkseal commented 7 years ago

Hello and thanks for your feedback.

I'm currently using TS 2.1.4.0 (Dev14) For Visual Studio 2015, which is the latest version available as of December 22, 2016 (download link here), and everything seems to be fine without any change to the code as it's written in the book and in the GitHub project:

This will also fix the "Invalid module name in augmentation, module '../../Observable' cannot be found" issue outlined in pages 47-48 of the book, so the suggested workaround of downloading an updated typescriptServices.js file shouldn't be needed anymore. However, for those who still need that file, here's the updated URL since the address written in the book is now returning a 404 - not found error:

https://raw.githubusercontent.com/Microsoft/TypeScript/Fix8518-Dev12/lib/typescriptServices.js

If you're still experiencing problems with TS, I strongly suggest to uninstall all TS for Visual Studio and then re-install the 2.1.4.0 build (or above), then restart VS2015 and see if everything is working properly.

Darkseal commented 7 years ago

I'm reopening this to share this workaround I found to overcome a rather common issue which is happening due to this DefinitelyTyped/core-js issue which strongly affects the Visual Studio TypeScript compiler.

The compilation errors you can receive are the following:

Error TS2693 Build:'Map' only refers to a type, but is being used as a value here.
Error TS2693 Build:'Promise' only refers to a type, but is being used as a value here.
Error TS2693 Build:'Set' only refers to a type, but is being used as a value here.
Error TS2304 Build:Cannot find name 'Iterable'.
Error TS2304 Build:Cannot find name 'IterableIterator'. Error TS2304 Build:Cannot find name 'MapConstructor'.
Error TS2304 Build:Cannot find name 'Iterator'.
Error TS2304 Build:Cannot find name 'PromiseConstructor'.
Error TS2304 Build:Cannot find name 'PropertyKey'.
Error TS2304 Build:Cannot find name 'SetConstructor'.
Error TS2304 Build:Cannot find name 'Symbol'.
Error TS2304 Build:Cannot find name 'WeakMapConstructor'.
Error TS2304 Build:Cannot find name 'WeakSetConstructor'. Error TS2339 Build:Property 'for' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'hasInstance' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'isConcatSpreadable' does not exist on type 'SymbolConstructor'. Error TS2339 Build:Property 'iterator' does not exist on type 'SymbolConstructor'. Error TS2339 Build:Property 'keyFor' does not exist on type 'SymbolConstructor'. Error TS2339 Build:Property 'match' does not exist on type 'SymbolConstructor'. Error TS2339 Build:Property 'replace' does not exist on type 'SymbolConstructor'. Error TS2339 Build:Property 'search' does not exist on type 'SymbolConstructor'. Error TS2339 Build:Property 'species' does not exist on type 'SymbolConstructor'. Error TS2339 Build:Property 'split' does not exist on type 'SymbolConstructor'. Error TS2339 Build:Property 'toPrimitive' does not exist on type 'SymbolConstructor'. Error TS2339 Build:Property 'toStringTag' does not exist on type 'SymbolConstructor'.
Error TS2339 Build:Property 'unscopables' does not exist on type 'SymbolConstructor'.

.. and so on.

The problem is due to an internal issue within that third-party library. We can fix that by specifying a fixed/unaffected version, so our project won't update it anymore with the latest build (which is causing the issue).

In order to do that open the project's package.json file and replace this:

  "scripts": {
    "postinstall": "typings install dt~core-js --global"
  }

with this:

  "scripts": {
    "postinstall": "typings install dt~core-js@0.9.7+20161130133742 --global"
  }

I will release a GitHub patch later today to fix the source code as well.

N.B.: There are many other possible ways to work around this problem: I chose this one because it doesn't require any significative change to the source code, thus making it easier to pull off for those who purchased the book.