Skip to content

Microsoft.TypeScript.MSBuild 5.1.x builds fail in Visual Studio 2019 due to always using VS's private node.exe v12 #54686

Closed

Description

@daiplusplus

Bug Report

  • After updating from Microsoft.TypeScript.MSBuild 4.5.3 to 5.1.3 my builds fail with the SyntaxError: Unexpected token '?' error, which is mentioned in the announcement blog post.

  • This happens because:

    • TypeScript 5.1 requires Node.js 14+
    • But Visual Studio 2019 always uses its own private node.exe version 12.20 to run TypeScript's tsc.js.
    • There does not seem to be a way to configure my MSBuild project to use my systemwide node.exe (version 18).
    • The announcement post does not mention any workaround steps or solution - nor any intentionally breaking compatibility with VS 2019.
  • I looked inside the 5.1.3's Microsoft.TypeScript.targets file and saw it uses the <NodePath> MSBuild property to resolve the path to node.exe - however this always uses $(MSBuildExtensionsPath)\Microsoft\VisualStudio\NodeJs which always resolves to C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\NodeJs on my computer.

    • There doesn't seem to be a way to override or force-set this property in a .csproj project file: my explicit <NodePath>C:\Program Files\nodejs<NodePath> is always ignored.

🔎 Search Terms

🕗 Version & Regression Information

Since updating from Microsoft.TypeScript.MSBuild version 4.5.3 to 5.1.3 I got stung by the SyntaxError: Unexpected token '?' error, which is mentioned in the announcement blog post.

The change was in this PR: #53291

  • This is a crash (insofar as "node.exe exited with code 1" is a crash)
  • This changed between versions 4.x and 5.1
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because

⏯ Playground Link

N/A

💻 Code

N/A

🙁 Actual behavior

  1. Install NodeJS 18+ systemwide (using the official installer).
  • When I open a new cmd prompt and run where node it gives me C:\Program Files\nodejs\node.exe which is v18.16.0 - this happens in both a "normal" cmd prompt as well as the "Developer Command Prompt for VS 2019" version.
  1. Create an ASP.NET Core project in VS2019 v16.11.26 (I'm targeting .NET Core 3.1)
  2. Add the Microsoft.TypeScript.MSBuild NuGet reference - I did it by adding <PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.1.3" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" /> directly to the <ItemGroup> in the ASP.NET Core project .csproj.
  3. Add a tsconfig.json file with "target": "es2022".
  4. Add a TypeScript .ts file with some code in it.
  5. Build the project from within VS (Menu > Build > Build Solution).
  6. This error will appear in the Error List:
Severity	Code	Description	Project	Path	File	Line	Source
Error	MSB6006	"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\NodeJs\node.exe" exited with code 1.	MyProject	C:\Users\David\.nuget\packages\microsoft.typescript.msbuild\5.1.3\tools	C:\Users\David\.nuget\packages\microsoft.typescript.msbuild\5.1.3\tools\Microsoft.TypeScript.targets	485	Build

🙂 Expected behavior

  • I expected the Microsoft.TypeScript.MSBuild package to verify that the version of node.exe that it's using is known compatible and if not to output a warning (not an error) - and if not compatible to output instructions on how to specify the exact path of node.exe to run.
  • I expected setting <NodePath> explicitly in my main <Project><PropertyGroup> to work. However it is ignored because Microsoft.TypeScript.targets always overwrites it.

Activity

  1. changed the title [-]Microsoft.TypeScript.MSBuild 5.1.x builds fail in Visual Studio 2019 due to always ussing VS's private node.exe v12[/-] [+]Microsoft.TypeScript.MSBuild 5.1.x builds fail in Visual Studio 2019 due to always using VS's private node.exe v12[/+] on Jun 17, 2023
  2. jakebailey commented on Jun 17, 2023

    @jakebailey
    Member
  3. joj commented on Jun 21, 2023

    @joj
    Member
  4. HolgerJeromin commented on Jun 23, 2023

    @HolgerJeromin
    Contributor

    Hacking in the registry is the recommend way to support VS2019?
    This is no ancient version, but got an update 10 days ago.

    \packages\Microsoft.TypeScript.MSBuild.5.1.3\tools\Microsoft.TypeScript.targets is from this repo, so IMO it should be possible here to support global installed node without replacing unmaintained node.exe in VS2019 (which would be a good thing neitherless).

  5. daiplusplus commented on Jun 23, 2023

    @daiplusplus
    Author

    Just in case someone from the future needs this workaround after developercommunity.visualstudio.com disappears (remember connect.ms? I remember...), So I've reposted it here:

    The issue is that Visual Studio 2019 ships with Node 12, and TypeScript 5.1 is using newer idioms that are supported in Node 14 and up. The workaround is to make Visual Studio use Node 16. To do that:

    1. Install Node 16 from nodejs.org. (We tested Node 16 and Node 14 and both work correctly with Visual Studio 2019)
      Modify the registry to point to the node you installed.
    2. Add a string value on HKCU\Software\Software\Microsoft\VisualStudio\16.0_xxx\TypeScriptLanguageService, named “CustomNodePath”. By default, the installer will install in c:\Pogram Files\nodejs\node.exe.
    3. After that, VS should be using node 16 and everything should work as before.

    For the record, at the time of posting even Node 16 is out-of-date, with the current LTS version being 18.16.1 - and the latest being 20.3.1, so I'm not sure testing only up-to Node 16 was a good idea.

    I won't be able to try this out for a while - I'll report back after testing the above reg change with Node 18, and if I encounter any issues I'll try Node 16.

  6. cbries commented on Jul 24, 2023

    @cbries

    A workaround for your projects can look like this tested with 5.02-beta in Vs19.

      <Target Name="ReTargetNodePath" BeforeTargets="CompileTypeScript">
        <PropertyGroup>
          <NodePath>C:\Program Files\nodejs\node.exe</NodePath>
        </PropertyGroup>
      </Target>
    

    This will set the globally installed node.exe variant for your build.

  7. HolgerJeromin commented on Jul 25, 2023

    @HolgerJeromin
    Contributor

    Christian Benjamin Ries (@cbries)
    Or more generic (will cover more msbuild targets):
    (note that this code needs to be added to your Visual Studio Project file.

    <Target Name="ReTargetNodePath" BeforeTargets="$(CompileDependsOn)">
        <PropertyGroup>
            <NodePath>C:\Program Files\nodejs\node.exe</NodePath>
        </PropertyGroup>
    </Target>
  8. ga5tan commented on Oct 10, 2023

    @ga5tan

    Holger Jeromin (@HolgerJeromin) worked for me, except had to remove node.exe from the NodePath:

    C:\Program Files\nodejs\
  9. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions