1

I have this Typescript project, that must be compiled to AMD and ES3. When I modify a file and save, the compile on save works just fine. However, when I build my solution, it re-compiles everything to commonjs (actually the --module flag is not provided so I just assume this is what's selected) and ES5.

I've checked the .csproj for the proper config

<TypeScriptModuleKind>AMD</TypeScriptModuleKind>

I've added a tsconfig.json at the root and also at the .ts files location without any success.

What am I missing? Why is it using the right config for compile on save but not when I'm building the project? Also, randomly I'm getting the "Build: Cannot compile modules unless the --module flag is provided." error.

Evan Carslake
  • 2,267
  • 15
  • 38
  • 56
Frank
  • 767
  • 5
  • 17
  • Possible duplicate of http://stackoverflow.com/questions/32273429/cannot-compile-modules-unless-the-module-flag-is-provided/32274106#32274106. There's a bug in VS 2015. So in default scenario it simply ignores you config and uses a default one – Artiom Sep 01 '15 at 18:41

2 Answers2

0

I've found out that there is an issue (that is resolved in tsc 1.6) and that the .csproj has to be modified. THe PropertyGroup's condition must be changed to specify one without a platform.

https://github.com/Microsoft/TypeScript/issues/4300

Frank
  • 767
  • 5
  • 17
0

Or you can choose to compile using tsc from the command line directly (which can be installed using npm install -g typescript), as long as you have a valid tsconfig.json file that specifies the module system and targeted ES version.

zhengbli
  • 702
  • 5
  • 24
  • Yes, compiling from the command line would work. I saw a post that would put all *.ts files inside a text file, and then input that file to the compiler. Although, when I debug the solution, it builds the project and overwrites all the compiled files. (http://stackoverflow.com/a/16433677/981308) – Frank Aug 31 '15 at 20:27
  • I don't think you need to merge all the .ts files. If you don't specify a `files` array in the tsconfig.json, it will implicitly include every .ts file in the same path. If you do specify, it will include only the files you told it to include. The details can be found at: https://github.com/Microsoft/TypeScript/wiki/tsconfig.json – zhengbli Aug 31 '15 at 20:33
  • Oh thanks, I missed that part about not specifying a files array. I was under the impression that the tsconfig.json was not being used since it wasn't compiling in the configurations I specified in it (module amd) – Frank Aug 31 '15 at 20:39