spoonraker spoonraker - 11 months ago 153
TypeScript Question

TFS Build fails for Angular 2 application (TypeScript errors), but everything builds fine locally

I am using Visual Studio 2015 with Update 3 installed. I have a solution that contains an Angular 2 application written in TypeScript. This application was added to the solution by following Angular's own "5 minute quickstart" guide: https://angular.io/guide/quickstart

The angular application isn't even complete, in fact it has barely started development. All of the configuration files for the angular 2 project were taken directly from that guide and haven't been modified.

The solution builds just fine on my local machine. However, when I do a TFS check-in which kicks off a build the solution fails to build on the remote build server.

I am getting the following errors in the MSBuild step, and they're all TypeScript related:


  • Error TS2307: Build: Cannot find module '@angular/core'.

  • Error TS1219: Build: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning

  • Error TS2315: Build: Type 'any' is not generic.

  • Error TS1148: Build: Cannot compile modules unless the '--module' flag is provided

  • Error TS2304: Build: Cannot find name 'it'.



Most of those errors are repeated numerous times pointing at various pieces of the angular 2 app. There are 29 errors in total.

The interesting part is that every one of those errors in the build log is followed by a reference to the .csproj file which contains the angular application.

It is my understanding that TypeScript files should be compiled based on configuration properties defined in the tsconfig.json file, and not the properties of the Visual Studio project. In fact, when I open the solution locally and attempt to modify the TypeScript configuration from the properties in Visual Studio, it tells me that these properties are disabled due to the fact that a tsconfig.json file is present.

Again, everything builds fine locally, zero errors. It only fails to build on the remote build server.

So does anybody have any ideas here? Is the remote build server perhaps not up-to-date and therefore not reading my tsconfig.json file?

just to be thorough, here is my tsconfig.json file...

{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
},
"compileOnSave": true
}


EDIT

Update: Ok, I think I'm narrowing in on this problem. It seems that on the TFS build my tsconfig.json is definitely not being read.

Here is the log from when I run MSBuild locally...

PreComputeCompileTypeScriptWithTSConfig:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe --project "C:\[MY PATH GOES HERE]\tsconfig.json"
CompileTypeScriptWithTSConfig:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\tsc.exe --project "C:\[My PATH GOES HERE]\tsconfig.json"


But here is what's happening on the remote TFS build...

PreComputeCompileTypeScript:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.5\tsc.exe --sourcemap --target ES5 --noEmitOnError COMPUTE_PATHS_ONLY
CompileTypeScript:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.5\tsc.exe --sourcemap --target ES5 --noEmitOnError


So... my build server is using TypeScript 1.5 while locally I have 1.8. And of course 1.8 is when improved support for tsconfig.json was introduced into Visual Studio. Hopefully all I have to do is get somebody to update TypeScript on the TFS server.

Answer Source

You'd better to make sure the environment on your build sever(build agent) are as same as your local. This will greatly reduce the risk of build failures.

In your situation, try to update TypeScript 1.5 to version 1.8 and queue the build again. If it's still not work, you can try to build manually on the build agent ( machine) not through tfs to narrow down the issue whether related to agent environment or the TFS build definition settings.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download