Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use DartSassHost in local dotnet tool #4

Closed
sergeyzwezdin opened this issue Jan 9, 2022 · 15 comments
Closed

Unable to use DartSassHost in local dotnet tool #4

sergeyzwezdin opened this issue Jan 9, 2022 · 15 comments

Comments

@sergeyzwezdin
Copy link

DartSassHost crashed silently when trying to use it as part of the local dotnet tool.

Steps to reproduce:

  1. Clone the sample project - https://github.com/sergeyzwezdin/dotnet-tool-DartSassHost/tree/master/dartsasshost-compiler
  2. Open cloned project folder, build.
  3. dotnet pack dartsasshost-compiler.csproj, save the path where is a package created, for example:

Successfully created package '/Users/sergeyzwezdin/Temp/dotnet-tool-DartSassHost/dartsasshost-compiler/bin/Debug/dartsasshost-compiler.1.0.0.nupkg'.

In this example we need /Users/sergeyzwezdin/Temp/dotnet-tool-DartSassHost/dartsasshost-compiler/bin/Debug/

  1. Create a new directory somewhere else, the next steps should be run from there:
  2. dotnet new tool-manifest
  3. dotnet tool install dartsasshost-compiler --version 1.0.0 --add-source=/Users/sergeyzwezdin/Temp/dotnet-tool-DartSassHost/dartsasshost-compiler/bin/Debug/ < replace path here
  4. Put some test.scss file into the directory
  5. dotnet tool run dartsasshost-compiler test.scss

Normally, this should return compiled code like this:
2022-01-09 at 23 08 03

But if we use it as a local dotnet tool it will fail silently and nothing is displayed:
2022-01-09 at 23 08 49

Also, it is interesting that it works okay if we install the tool globally. 🤔

@Taritsyn
Copy link
Owner

Hello, Sergey!

I have tested your package on different operating systems.

On Windows 10 (x64) everything works:

windows-10-x64

On Ubuntu 20.04 (x64) everything works too:

ubuntu-20 04-x64

A well-known bug did not allow testing on macOs 10.13. But I rebuilt your package with a dependency on the JavaScriptEngineSwitcher.Jint version 3.16.0 Preview (works correctly only under .NET 5+) instead of the JavaScriptEngineSwitcher.V8, and everything works too:

macos-10 13-x64

Unfortunately, it is no possibility yet to test the package on macOs 12.

@sergeyzwezdin
Copy link
Author

Hello Andrey!
Thank you for your explanation. Does it mean that WebCompiler should you Jint instead of V8?

@Taritsyn
Copy link
Owner

For now, I recommend you to check how the Excubo.WebCompiler version 3.0.1 Preview 2 works on macOS 12.1.

@sergeyzwezdin
Copy link
Author

@Taritsyn the same result with 3.0.1-preview.2 - just crashes silently

2022-01-10 at 21 28 50

@Taritsyn
Copy link
Owner

Then I recommend that you try to build your own package based on Jint.

@sergeyzwezdin
Copy link
Author

So, is that right that it is not going to be fixed?

@Taritsyn
Copy link
Owner

Must first understand whether the modification with Jint works on your machine.

@Taritsyn
Copy link
Owner

Can you show me the contents of test.scss file?

@sergeyzwezdin
Copy link
Author

.test { color: red; }

@Taritsyn
Copy link
Owner

It's good that it's not empty ;-) With an empty file, this error is reproduced completely:

windows-10-x64-empty

In general, what's stopping you from using the Node.js-version of this tool from Google?

@sergeyzwezdin
Copy link
Author

In general, what's stopping you from using the Node.js-version of this tool from Google?

In general, the team does not want to install Node tool to be able to build the project, but if it won't work that's the still option.

@Taritsyn
Copy link
Owner

Hello, Sergey!

Today I had the opportunity to run your original example on macOS 12.1 (x64). The error was reproduced, but under certain conditions.

The error reproduces well on a clean operating system with the .NET 6.0.101 SDK installed:

before-dotnet-runtime-5 0 13-osx-x64-installation-marked

If install the .NET 5.0.13 Runtime, then this error no longer occurs:

after-dotnet-runtime-5 0 13-osx-x64-installation-marked

But it happens because .NET perceives the operating system as macOS 11, although the operating system itself has not changed:

about-this-mac

@sergeyzwezdin
Copy link
Author

@Taritsyn thank you for your investigation. Do you think that the problem is .NET itself, not DartSassHost?
.NET 5 is not an option since the requirement is to run SASS compilation on Apple Silicone as well.
But anyway, we're going to use a native node to build the assets, so it's up to you to continue the issue investigation.

@Taritsyn
Copy link
Owner

Hello, Sergey!

Apparently, this error occurs at the Microsoft ClearScript.V8 library level, because when using the JavaScriptEngineSwitcher.ChakraCore and JavaScriptEngineSwitcher.Jint modules everything works correctly.

Now I am trying to reproduce this error without using the DartSassHost library.

@Taritsyn
Copy link
Owner

It seems that the “Net 6 test runners support” issue and this error have the same reason.

If modify your example as follows:

dartsasshost-compiler.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <RootNamespace>dartsasshost_compiler</RootNamespace>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PackAsTool>true</PackAsTool>
    <ToolCommandName>dartsasshost-compiler</ToolCommandName>
    <AssemblyName>dartsasshost-compiler</AssemblyName>

  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.ClearScript.V8" Version="7.2.1" />
    <PackageReference Include="Microsoft.ClearScript.V8.Native.win-x86" Version="7.2.1" />
    <PackageReference Include="Microsoft.ClearScript.V8.Native.win-x64" Version="7.2.1" />
    <PackageReference Include="Microsoft.ClearScript.V8.Native.win-arm64" Version="7.2.1" />
    <PackageReference Include="Microsoft.ClearScript.V8.Native.linux-x64" Version="7.2.1" />
    <PackageReference Include="Microsoft.ClearScript.V8.Native.linux-arm" Version="7.2.1" />
    <PackageReference Include="Microsoft.ClearScript.V8.Native.linux-arm64" Version="7.2.1" />
    <PackageReference Include="Microsoft.ClearScript.V8.Native.osx-x64" Version="7.2.1" />
    <PackageReference Include="Microsoft.ClearScript.V8.Native.osx-arm64" Version="7.2.1" />
  </ItemGroup>

  <ItemGroup>
    <Content Include="package.csproj" />
  </ItemGroup>

</Project>

Program.cs

using Microsoft.ClearScript.V8;

using (var engine = new V8ScriptEngine())
{
    Console.WriteLine("Start script execution...");

    engine.Execute(@"var count = 0;

for (var i = 1; i < 1000000; i++) {
    count++;
}"
    );
    var count = (int)engine.Evaluate("count");

    Console.WriteLine("Number of iterations: {0}", count);
}

Then with a clean installation of the .NET 6.0.101 SDK we will get a similar error:

before-dotnet-runtime-5 0 13-osx-x64-installation-marked

And if the .NET 5.0.13 Runtime is also installed, the result will be correct:

after-dotnet-runtime-5 0 13-osx-x64-installation-marked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants