I recently encountered an issue with changing the module kind used by the transpiler in Visual Studio. Despite updating the <TypescriptModuleKind>
in the project's project.csproj
file from commonjs
to AMD
, the transpiler still defaults to using commonjs
.
To replicate the problem, follow these steps:
- Install the necessary TypeScript addons - Typescript Tools, Typescript Build, and Rich Newman's Typescript HTML Application Template.
- Create a new project using the provided template.
- Check the
project.csproj
file to confirm that it contains
.<TypescriptModuleKind>commonjs</TypescriptModuleKind>
- Start the server and verify that the application runs without any errors.
- Edit the
app.js
file and notice how it is structured. - Add the prefix
export
to theapp.ts
file and refresh the page to observe the error messageexports is undefined
. - Update the
tsconfig.json
file to use"module": "amd"
and re-transpile the TypeScript files. - Verify the changes in the generated
app.js
file after the modification. - Follow the provided link for further instructions on setting up
requirejs
. - Test in the browser to ensure no errors are present.
- Rename or move the
tsconfig.json
file and restart the server to see if the error persists. - Confirm that modifying the
project.csproj
file also leads to the same error.
This experiment demonstrates that Visual Studio may not be properly utilizing the tsconfig.json
file or respecting its TypescriptModuleKind
configuration value.
Further investigation into how Visual Studio handles TypeScript build configurations suggests that using the --module
switch directly can yield more reliable results than relying on the project settings alone.
Is there a way to ensure that Visual Studio respects the tsconfig.json
file and its specified TypescriptModuleKind
setting?