Geeks With Blogs

News Please visit me at my new blog!!

profile for Aligned at Stack Overflow, Q&A for professional and enthusiast programmers
"free in Christ Jesus from the law of sin and death." Romans 8:2 (ESV) Check out the Falling Plates video on YouTube.
more about the Gospel
And then listen to Francis Chan speaking at LifeLight in SD.

Programming and Learning from SD

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 for some idea.

My example is:

 <script type="text/javascript">
        ready(function () {
            // need to make sure indexTSViewModel is available for require first
           // beware of the paths!
            require(['Scripts/ViewModels/indexTsViewModel', 'Scripts/modules/jQueryAjaxDataService'],
                function (IndexTsViewModel, JQueryAjaxDataService) {
                    var typeScriptVm = new IndexTsViewModel.IndexTsViewModel(new JQueryAjaxDataService.JQueryAjaxDataService($));
                    var tsDiv = document.querySelector("#knockoutAreaWithTS");
                    ko.applyBindings(typeScriptVm, tsDiv);


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

Posted on Wednesday, September 2, 2015 9:00 PM TypeScript , RequireJS | Back to top

Comments on this post: VS 2015 and Typescript module flag

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Aligned | Powered by: