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
@daiplusplus

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.

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