Closed daiplusplus closed 1 year ago
@joj
This is a known issue, more details (and workaround) here: https://developercommunity.visualstudio.com/t/TypeScript-51-not-working-properly-on-V/10383037
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).
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:
- 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.
- Add a string value on
HKCU\Software\Software\Microsoft\VisualStudio\16.0_xxx\TypeScriptLanguageService
, named “CustomNodePath
”. By default, the installer will install inc:\Pogram Files\nodejs\node.exe
.- 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.
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.
@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>
@HolgerJeromin worked for me, except had to remove node.exe from the NodePath:
C:\Program Files\nodejs\
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:
node.exe
version 12.20 to run TypeScript'stsc.js
.node.exe
(version 18).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..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
version4.5.3
to5.1.3
I got stung by theSyntaxError: Unexpected token '?'
error, which is mentioned in the announcement blog post.The change was in this PR: https://github.com/microsoft/TypeScript/pull/53291
node.exe exited with code 1
" is a crash)⏯ Playground Link
N/A
💻 Code
N/A
🙁 Actual behavior
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.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
.tsconfig.json
file with"target": "es2022"
..ts
file with some code in it.This error will appear in the Error List:
🙂 Expected behavior
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.<NodePath>
explicitly in my main<Project><PropertyGroup>
to work. However it is ignored becauseMicrosoft.TypeScript.targets
always overwrites it.