VS 2015 and Typescript module flag

Typescript 1.5 allows you to import modules using the import statement.

import {DataService} from"../Modules/jQueryAjaxDataService";

In Visual Studio 2015, the   Build: Cannot compile modules unless the '--module' flag is provided stops me from proceeding.

Here are the steps to take to user AMD module loading in VS 2015.

  1. Edit the TypeScript Build Module System options in the properties of the web project. Make sure to change it for debug and release.
    1. I found this answer on StackOverflow.
  2. Edit the project file with a text editor and “just edit the file manually, change "'$(Configuration)|$(Platform)' == 'Debug|Any CPU'" to "'$(Configuration)' == 'Debug'"> and it should work again.” There is an issue about this on TypeScript
  3. Include the AMD system of your choice for the browser to use. TypeScript will compile the JavaScript with define( in the files.
    1. RequireJs is a good option.
  4. You may have to change some code if you are using document ready then using the script. Especially if the JavaScript files were just included in the source or using BundleConfig.cs before.
    1. Look at my GitHub Ajax example: in the Home/Index.cshtml. This works, but the path may not always be correct, so figuring out setting the require.config({ baseUrl: ‘ // check out http://stackoverflow.com/questions/1288046/how-can-i-get-my-webapps-base-url-in-asp-net-mvc for some idea.

My example is:

Hopefully this will help you get AMD and import in TypeScript working in Visual Studio 2015.

This article is part of the GWB Archives. Original Author: Aligned

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.