10

I've created a new .ts file in a webproject using VS2015. In the properties for the project under TypeScript Build I've checked Module System = AMD.

Then when trying to write a external module i get the following error.

Cannot compile modules unless the '--module' flag is provided.

Where do I provide the moduel flag?

2
  • I have the same issue. I've set detailed verbosity for build (Tools-> options) and I can see that module parameter is not passed to typescript compiler: tsc.exe --sourcemap --target ES5 --noEmitOnError --locale en-US. Pretty strange. Commented Aug 11, 2015 at 14:41
  • I have the same issue with VS Code. Documentation is still quite poor for VS Code. Even the most basic examples fail to compile. Commented Nov 23, 2015 at 13:41

3 Answers 3

6

It seems to be a bug with VS2015 RTM. The project TypeScript settings are saved incorrectly to the .csproj file, so the TypeScript compiler isn't reading them.

To fix:

  1. Right-click the project, unload it, then right click again and edit it.
  2. Search for <TypeScriptModuleKind>, and then locate the parent element, which should be called <PropertyGroup>.
  3. Look for the text "Any CPU" in the Condition attribute value, change it to "AnyCPU" -- i.e. remove the space.
  4. Search again and repeat the change in case you have TypeScript settings for other build conditions.

Note that until this bug is fixed, you'll need to edit the .csproj file to modify TypeScript settings. If you try to make the change from the project settings area, it will just generate new settings in the project file with the wrong condition value again.

Also, you may be reading about using a tsconfig.json file instead for providing the settings in VS2015. However, it seems that this capability is currently only implemented for the Website project type and not for Web Application projects.

Sign up to request clarification or add additional context in comments.

3 Comments

this also worked for me. Two things 1) It was <PropertyGroup> not <ParentGroup>` 2) I change the condition to <PropertyGroup Condition="'$(Platform)' == 'AnyCPU'"> this way it applies to all configurations
Thank you. I had to use the solution provided by @JonSquared to made the error go away.
I found that I had to set the module setting for each the different configurations as well, instead of just whichever I was presently using.
6

I couldn't make it work. Whatever I change in typescript section - it's ignored on build.

If I set verbosity to Detailed in Tools->Options->Build and run I can see that all my settings are ignored, including -module flag.

Just as workaround. Create a tsconfig.json file in root directory. And add in pre-build events "tsc" command. In this case it worked just fine.

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitAny": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": true
  }
}

enter image description here

Comments

1

You have updated the correct setting - the project properties does have setting for each build configuration, so make sure you have also ticked "AMD" under each configuration (for example, Debug and Release).

I often get caught by this when switching between configurations.

1 Comment

This was my first step so I could even get the <TypeScriptModuleKind> element in the project file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.