Description
Bug Report
-
After updating from
Microsoft.TypeScript.MSBuild
4.5.3 to 5.1.3 my builds fail with theSyntaxError: 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'stsc.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 tonode.exe
- however this always uses$(MSBuildExtensionsPath)\Microsoft\VisualStudio\NodeJs
which always resolves toC:\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.
- There doesn't seem to be a way to override or force-set this property in a
🔎 Search Terms
- "visual studio 2019" ( "node.exe" OR "node" ) typescript 5.1 version
- msbuild typescript 5.1 nodejs version
- Unrelated-but-related: Add the Node that comes with Visual Studio as a NodePath fallback in the .targets file in the Microsoft.TypeScript.MSBuild Nuget package #38247
- Related: Bump minimum Node to 14.17, ES to 2020 for TS 5.1 #53291
- Same issue: https://stackoverflow.com/questions/76421238/tsc-command-showing-syntaxerror-unexpected-token
- Related: MsBuild.TypeScript uses Node 32bit by default #32733
🕗 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
- Install NodeJS 18+ systemwide (using the official installer).
- When I open a new cmd prompt and run
where node
it gives meC:\Program Files\nodejs\node.exe
which isv18.16.0
- this happens in both a "normal" cmd prompt as well as the "Developer Command Prompt for VS 2019" version.
- Create an ASP.NET Core project in VS2019 v16.11.26 (I'm targeting .NET Core 3.1)
- 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
. - Add a
tsconfig.json
file with"target": "es2022"
. - Add a TypeScript
.ts
file with some code in it. - Build the project from within VS (Menu > Build > Build Solution).
- 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 ofnode.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 ofnode.exe
to run. - I expected setting
<NodePath>
explicitly in my main<Project><PropertyGroup>
to work. However it is ignored becauseMicrosoft.TypeScript.targets
always overwrites it.