Typescript: Major - Microsoft.TypeScript.MSBuild not working on Ubuntu when path to TSJavascriptFile contains spaces

Created on 26 Aug 2019  ·  6Comments  ·  Source: microsoft/TypeScript

TypeScript Tools Version:

3.6.0-beta
By the way why is this the output of tsc.js while I installed the latest stable version of the NuGet package (3.6.0), is it normal that a beta compiler is in the package? If so, shouldn't Microsoft.TypeScript.MSBuild-3.6.0 be marked as beta in NuGet?


Search Terms:
MSBuild

Expected behavior:

I am developping on Ubuntu using barebone emacs and mono. The project also uses C# so I leverage MSBuild (which I also quite enjoy as a build system). The csproj file is pretty much handcrafted, and I was able to build my project just fine for many years. This is a mature project, so I know that the problem is isolated to typescript.

I have followed the instructions mentioned on this page :
https://www.typescriptlang.org/docs/handbook/integrating-with-build-tools.html#msbuild

And I have of course adjusted the path to the files to match the path to the files installed by the NuGet package. I am expecting the project to build properly and typescript files to be compiled.

Actual behavior:

Unfortunately, when trying to build my project, I get an error saying that nodejs exited with error code 1. By increasing the verbosity of msbuild to see nodejs' call stack, I can see that nodejs crashes at the bootstrapping stage at

Function.Module._resolveFileName (module.js:547:15)

which means that the typescript file is not found. In msbuild's log in diagnotic mode, I have noticed that the path to tsc.js passed as a parameter to nodejs is not put within quotes while (for example) the path to the typescript files to compile are passed within quotes.

I have been able to confirm that this is indeed the problem as by invoking /usr/bin/nodejs directly in the shell I get the exact same error with the same call stack, while by putting the path within quotes tsc.js is properly executed.

I tried to naively patch Microsoft.Typescript.Targets to put single quotes around the TSJavascriptFile parameter of the VsTsc command at line 543 (in the definition of the Target CompileTypeScript - I do not use tsconfig files but TypeScriptCompile items in my csproj file so this is the target used), I tried to do that, but the path is totally messed up when I do so.

Turning TSJavascriptFile="$(TSJavascriptFile)" into TSJavascriptFile="'$(TSJavascriptFile)'" (single quotes added) and similar variants, turns for example

/dir1/dir2/my path with space

into

/dir1/dir2/my path with space"/dir1/dir2/my path with space"

when nodejs is invoked. So I guess the change may need to be done in TypeScript.Tasks.dll, but I am just guessing. I am targeting net45 and running on mono.

Bug Fixed

All 6 comments

Just to confirm that moving Microsoft.TypeScript.MSBuild to a location not containing any space in its path solves the problem and everything works fine. But this is not a sustainable solution.

I am hitting this issue both on 3.6 0 and 3.5.3.

By the way why is this the output of tsc.js while I installed the latest stable version of the NuGet package (3.6.0), is it normal that a beta compiler is in the package? If so, shouldn't Microsoft.TypeScript.MSBuild-3.6.0 be marked as beta in NuGet?

This particular question is tracked by https://github.com/microsoft/TypeScript/issues/32729

Assigning to @minestarks for now until we can determine where the problem is.

@nkosi23 in the meantime if you can produce a small repro, that would help greatly, since there's no overlap on our team of ubuntu users and msbuild users.

@sandersn @nkosi23 I got you covered, I have a small repro on WSL using the .NET CLI. The issue is in our NuGet package.

mkdir src
mkdir path\ with\ space
cd src
dotnet new web
echo > wwwroot/foo.ts
dotnet add package Microsoft.TypeScript.MSBuild -v 3.6.0 
dotnet build -v n --packages "../path with space"

@PranavSenthilnathan FYI - We probably need to use CommandLineBuilder in the tasks to handle paths gracefully.

Hooray for WSL! :tada:

Fixed for 3.7 in the MSBuild repo

Was this page helpful?
0 / 5 - 0 ratings