microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.58k stars 12.43k forks source link

Typescript compile on save setting in Visual studio is not honored #7911

Closed rkavalap closed 8 years ago

rkavalap commented 8 years ago

Repro steps: Edit a typescript file.

Expected behavior: If Tools -> Text Editor -> Typescript -> Project -> General If Compile on Save option unchecked equivalent js file should not be generated at the current location.

Current behavior: Generating a js file.

Earlier versions of ntvs had this in the project file for the behavior

<EnableTypeScript>true</EnableTypeScript>
<TypeScriptSourceMap>true</TypeScriptSourceMap>
<TypeScriptModuleKind>CommonJS</TypeScriptModuleKind>
<ToolsVersionPromptShown>1.7</ToolsVersionPromptShown>

Which was automatically generating the js file.

When I open a nodejs solution, I currently see it's automatically edited. But I don't see above setting changes getting added in the edit. I am currently not sure where it is getting controlled from.

Issue redirected from https://github.com/Microsoft/nodejstools/issues/832

pebezo commented 8 years ago

You need to add { "compileOnSave": true } to your tsconfig.json file. However, it doesn't seem to always follow it, or there are hidden errors... not sure; it's very flaky.

mhegazy commented 8 years ago

If you are using a tsconfig, set "compileOnSave": true in it. see http://www.typescriptlang.org/docs/handbook/tsconfig.json.html#compileonsave tsconfig

If you are not using a tsconfig.json file, then the project property pages should would be the place to set CompileOnSave. projectproperties

If you do not have a project file, i.e. open a ts file and start editing, then use Tools -> Text Editor -> Typescript -> Project -> General to turn compile on save on. tsconfig

hope that helps.

mhegazy commented 8 years ago

not sure; it's very flaky.

@pebezo, we would love to get to the bottom of any issues you are running into. can you share more infromaiton

pebezo commented 8 years ago

If I can come up with a repro I'll make sure to post it -- unfortunately it seems rather random. Sometimes right-clicking on the project and choosing "rebuild" works when just saving doesn't. Just "build" doesn't seem to work...

mhegazy commented 8 years ago

@pebezo what you are saying makes me think it could be https://github.com/Microsoft/TypeScript/issues/7247. i am assuming you have a tsconfig.json, if so, then build will work iff you touched the tsconfig.json, otherwise a rebuild is required.

rkavalap commented 8 years ago

@mhegazy @pebezo I neither have a tsconfig.json nor a compile on save option in my project properties. It's a nodejs tools project. A sample project https://github.com/rkavalap/NightWatchTest Project itself doesn't have .njsproj file checked in. But you can try this one as a reference.

I use gulp to transpile my typescript files to javascript. I am not sure how this a compiler issue. The setting I was referring earlier to is in the visual studio options which created the above referred xml fragment in my project file compileonsave

[EDIT]: I just re-read the wording of the checkbox, the expected behavior is different to what I am reporting. From the wording I believe files not included in the project file should be transpiled or not.

For my issue: But the edited files get transpiled on the fly which are already part of project as well.

mhegazy commented 8 years ago

this setting only controls loose files, i.e. open a random .ts file and save it. if you have project, ntvs or other, you need to set this in your project.

davlinski commented 8 years ago

This was working perfectly before VS2015 Update 2 (TS 1.8). Now it's not working at all. Only way I can get it to transpile is by performing a build/rebuild. No bueno.

mhegazy commented 8 years ago

@davlinski can you share more information about your project/setup.

davlinski commented 8 years ago

@mhegazy Sorry 'bout that! I restarted Visual Studio and it started working again. I added the setting mentioned above ("compileOnSave": true) to my tsconfig.json file and it wasn't working. I spoke (typed) before adhering to the cardinal rule of Windows; when all else fails...restart. Thank you!

rkavalap commented 8 years ago

@mhegazy Is there a setting that is currently exposed to not compile the ts file I just edited and saved. Below is my current my vs setup. I am unable to track this setting down.

Microsoft Visual Studio Enterprise 2015 Version 14.0.25123.00 Update 2 Microsoft .NET Framework Version 4.6.01038

Installed Version: Enterprise

Architecture and Modeling Tools 00322-90000-92003-AA742 Microsoft Architecture and Modeling Tools

UML® and Unified Modeling Language™ are trademarks or registered trademarks of the Object Management Group, Inc. in the United States and other countries.

LightSwitch for Visual Studio 2015 00322-90000-92003-AA742 Microsoft LightSwitch for Visual Studio 2015

Visual Basic 2015 00322-90000-92003-AA742 Microsoft Visual Basic 2015

Visual C# 2015 00322-90000-92003-AA742 Microsoft Visual C# 2015

Visual C++ 2015 00322-90000-92003-AA742 Microsoft Visual C++ 2015

Visual F# 2015 00322-90000-92003-AA742 Microsoft Visual F# 2015

Windows Phone SDK 8.0 - ENU 00322-90000-92003-AA742 Windows Phone SDK 8.0 - ENU

ASP.NET and Web Tools 2015 (RC1 Update 1) 14.1.20203.0 ASP.NET and Web Tools 2015 (RC1 Update 1)

ASP.NET Web Frameworks and Tools 2012.2 4.1.41102.0 For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013 5.2.40314.0 For additional information, visit http://www.asp.net/

Azure App Service Tools v2.7.1 14.0.11112.0 Azure App Service Tools v2.7.1

Common Azure Tools 1.7 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

HideMenu 1.0 Hides the Visual Studio main menu, similar to Windows Explorer and Internet Explorer

JavaScript Language Service 2.0 JavaScript Language Service

JavaScript Project System 2.0 JavaScript Project System

JetBrains ReSharper Ultimate 2015.2 Build 103.0.20150818.200216 JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2016 JetBrains, Inc.

Microsoft Azure HDInsight HQL Service 2.0.2900.0 Language service for Hive query

Microsoft Azure HDInsight Tools for Visual Studio 2.0.2900.0 An integrated development environment for HDInsight application development.

Microsoft Azure Mobile Services Tools 1.4 Microsoft Azure Mobile Services Tools

Microsoft Azure Tools 2.8 Microsoft Azure Tools for Microsoft Visual Studio 2015 - v2.8.40211.2

Microsoft Team Foundation Server 2015 Power Tools 14.0 Power Tools that extend the Team Foundation Server integration with Visual Studio.

Microsoft Visual Studio Process Editor 1.0 Process Editor for Microsoft Visual Studio Team Foundation Server

Node.js Tools 1.1.40329.04 Adds support for developing and debugging Node.js apps in Visual Studio

Node.js Tools - Profiling 1.1.40329.04 Profiling support for Node.js projects.

NPM Task Runner 1.3.59 Adds support for package.json's NPM scripts in the Task Runner Explorer

NuGet Package Manager 3.4.3 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2015 ENU 14.0.23025 Microsoft Office Developer Tools for Visual Studio 2015 ENU

PreEmptive Analytics Visualizer 1.2 Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

Python Tools for Visual Studio 2.2.40315.00 Python Tools for Visual Studio provides IntelliSense, projects, templates, Interactive windows, and other support for Python developers.

Python Tools for Visual Studio - Django Integration 2.2.40315.00 Provides templates and integration for the Django web framework.

Python Tools for Visual Studio - Profiling Support 2.2.40315.00 Profiling support for Python projects.

SQL Server Data Tools 14.0.60311.1 Microsoft SQL Server Data Tools

TypeScript 1.8.29.0 TypeScript tools for Visual Studio

Visual Studio Spell Checker VSSpellChecker An editor extension that checks the spelling of comments, strings, and plain text as you type. https://GitHub.com/EWSoftware/VSSpellChecker

Visual Studio Tools for Apache Cordova Update 8 Visual Studio Tools for Apache Cordova

Visual Studio Tools for Universal Windows Apps 14.0.25123.00 The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

Windows Installer XML Toolset 3.10.2.2516 Windows Installer XML Toolset version 3.10.2.2516 Copyright (c) Outercurve Foundation. All rights reserved.

Workflow Manager Tools 1.0 1.0 This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin 4.0.0.1717 (1390b70) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android 6.0.0.35 (d300845) Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS 9.3.99.33 (ea30b32) Visual Studio extension to enable development for Xamarin.iOS.

mhegazy commented 8 years ago

@rkavalap can you share your project? or at least the project file.

rkavalap commented 8 years ago

@mhegazy here you go. Github doesn't support the nodejs project file. So copy pasting it below. I can repro this with my sample project on github. https://github.com/rkavalap/NightWatchTest

Earlier I was under the assumption of Task runner explorer was causing an issue. But I uninstalled the extention and still find the issue to repro

I find this issue to be closely related https://github.com/Microsoft/TypeScript/issues/5638

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{09e167bc-f3de-4c00-8b25-01239456b211}</ProjectGuid>
    <ProjectHome />
    <ProjectView>ShowAllFiles</ProjectView>
    <StartupFile>node_modules/nightwatch/bin/runner.js</StartupFile>
    <WorkingDirectory>.</WorkingDirectory>
    <OutputPath>.</OutputPath>
    <ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    <ScriptArguments>-t buildOutput/JavaScript1.js --env devtest-chrome-win8</ScriptArguments>
    <StartWebBrowser>True</StartWebBrowser>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
  <PropertyGroup Condition="'$(Configuration)' == 'Release'" />
  <ItemGroup>
    <Content Include="configs\capabilities.json5" />
    <Content Include="configs\defaults.json5" />
    <Content Include="configs\deployments.json5" />
    <Content Include="configs\TestConfigData\ci.json5" />
    <Content Include="configs\TestConfigData\devtest.json5" />
    <Content Include="configs\TestConfigData\pprod.json5" />
    <Content Include="nightwatch.conf.js" />
    <Content Include="package.json" />
    <Content Include="README.md" />
    <TypeScriptCompile Include="globalsModule.js" />
    <TypeScriptCompile Include="tests\JavaScript1.ts" />
    <TypeScriptCompile Include="tests\JavaScript2.ts" />
    <TypeScriptCompile Include="tests\JavaScript3.ts" />
    <TypeScriptCompile Include="tests\JavaScript4.ts" />
    <TypeScriptCompile Include="typings\nightwatch-custom\custom-assertions.d.ts" />
    <TypeScriptCompile Include="typings\nightwatch-custom\custom-commands.d.ts" />
    <TypeScriptCompile Include="typings\nightwatch-custom\custom-reporters.d.ts" />
    <TypeScriptCompile Include="typings\nightwatch\nightwatch.d.ts" />
    <TypeScriptCompile Include="typings\nightwatch-custom\page-objects.d.ts" />
    <TypeScriptCompile Include="typings\node\node.d.ts" />
    <TypeScriptCompile Include="typings\tsd.d.ts" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="configs\" />
    <Folder Include="configs\TestConfigData\" />
    <Folder Include="lib\" />
    <Folder Include="lib\common\" />
    <Folder Include="lib\common\utils\" />
    <Folder Include="lib\custom-assertions\" />
    <Folder Include="lib\custom-commands\" />
    <Folder Include="lib\custom-reporters\" />
    <Folder Include="lib\page-objects\" />
    <Folder Include="tests" />
    <Folder Include="typings\" />
    <Folder Include="typings\nightwatch-custom\" />
    <Folder Include="typings\nightwatch\" />
    <Folder Include="typings\node\" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="lib\custom-reporters\reporter.js" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <!--Do not delete the following Import Project.  While this appears to do nothing it is a marker for setting TypeScript properties before our import that depends on them.-->
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="False" />
  <Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsTools.targets" />
  <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
        <WebProjectProperties>
          <UseIIS>False</UseIIS>
          <AutoAssignPort>True</AutoAssignPort>
          <DevelopmentServerPort>0</DevelopmentServerPort>
          <DevelopmentServerVPath>/</DevelopmentServerVPath>
          <IISUrl>http://localhost:48022/</IISUrl>
          <NTLMAuthentication>False</NTLMAuthentication>
          <UseCustomServer>True</UseCustomServer>
          <CustomServerUrl>http://localhost:1337</CustomServerUrl>
          <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
        </WebProjectProperties>
      </FlavorProperties>
      <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}" User="">
        <WebProjectProperties>
          <StartPageUrl>
          </StartPageUrl>
          <StartAction>CurrentPage</StartAction>
          <AspNetDebugging>True</AspNetDebugging>
          <SilverlightDebugging>False</SilverlightDebugging>
          <NativeDebugging>False</NativeDebugging>
          <SQLDebugging>False</SQLDebugging>
          <ExternalProgram>
          </ExternalProgram>
          <StartExternalURL>
          </StartExternalURL>
          <StartCmdLineArguments>
          </StartCmdLineArguments>
          <StartWorkingDirectory>
          </StartWorkingDirectory>
          <EnableENC>False</EnableENC>
          <AlwaysStartWebServerOnDebug>False</AlwaysStartWebServerOnDebug>
        </WebProjectProperties>
      </FlavorProperties>
    </VisualStudio>
  </ProjectExtensions>
</Project>
mhegazy commented 8 years ago

@rkavalap the fix is in https://github.com/rkavalap/NightWatchTest/pull/2/commits/a3066a44740e7a615f56026e9ee52ad1527b3939

The better fix is to add a tsconfig.json to your project.

{
    "compileOnSave": false,
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5"
    }
}

you can find the full documentation for the properties in http://www.typescriptlang.org/docs/handbook/compiler-options-in-msbuild.html

dcumin39 commented 8 years ago

I am having the same issue. >net 4.6.1. I save the ts file and the quickest workaround i have found is to manually deleted both the .map and .js file. It would be nice if it automatically compiled on save like the Project Options Indicate it should.

Legends commented 7 years ago

I can confirm, that is sometimes does not compile on save. VS 2015 Update 3, tsconfig.js. I put the directive "compileOnSave": true, under compilerOptions now, before that it was below, don't know if this will have any impact on reliability

{
    "compilerOptions": {
        "compileOnSave": true,
        "module": "amd", // system
        "target": "es5",
        "allowJs": false,
        "noImplicitAny": false,
        "removeComments": true,
        "preserveConstEnums": true,
        "sourceMap": true,
        "allowUnreachableCode": false,
        "listFiles": true,
        "typeRoots": [ "node_modules/@types/" ],
        "watch": false,
        //"noLib": true,
        "suppressImplicitAnyIndexErrors": false,
        "noEmitOnError": true
    },
    "compileOnSave": true,
    //"files": [""],
    "exclude": [
        "node_modules",
        "Scripts-Built",
        "**/*.spec.ts"
    ],
    "include": [
        "scripts/**/*"
    ]
}
wgutierrezr commented 6 years ago

Using tsconfig.json or without, Visual Studio 2017 Professional is not updating site.js when running in Debug mode in my case (Core 2 MVC project)

ghost commented 6 years ago

I have the same issue. Whenever i save or make a new change in the file, the TSC WATCH doesnt do the change. It is doing it only if i close and restart it....i receive an error like: tsconfig.json(4,6): error TS5023: Unknown compiler option 'compileOnSave'.

My settings from tsconfig.json are:

{

   "compilerOptions": {
     "compileOnSave": true,
     "module": "commonjs",
     "outDir": "outnew/",
     "noImplicitAny": true,
     "removeComments": true,
     "preserveConstEnums": true
   },
   "include": [
     "*"
   ],
   "exclude": [
       "node_modules",
       "**/*.spec.ts"
   ]
 }
AdamSharon commented 6 years ago

This is still an issue, but the problem now is slightly different - the version of typescript is not honoured : I have a project that is configure with TypeScript 2.2, and the "Compile On Save" is compiling according to the latest on my machine (2.5), so it issues me compiling errors since I am not working according to the strict "non-weak" convention of 2.5. the regular Build still compiles fine.

by using the tsconfig.json I was able to make visual studio compile it on save anyway, but the IDE still shows me all the errors.

Also it should work for those of us who choose to work with project options.

@iocohen - you settings are wrong, the "CompileOnSave" should not be in the options, but under the root brackets. this works for me: { "compileOnSave": true, "compilerOptions": { "noImplicitAny": false, "noEmitOnError": false, "removeComments": false, "sourceMap": false, "target": "es5", "module": "commonjs", "skipLibCheck": true }, "exclude": [ "node_modules", "wwwroot" ] }

rkorszun commented 6 years ago

@AdamSharon try re-install TypeScript SDK from here https://www.microsoft.com/en-us/download/details.aspx?id=55258 and restart VS

AdamSharon commented 6 years ago

@rkorszun there is no 2.2 on that list, also I tried adding manually the Release ZIP from this repo but it not solve the issue.