LibSassHost icon indicating copy to clipboard operation
LibSassHost copied to clipboard

Error: File to import not found or unreadable

Open calebsandfort opened this issue 5 years ago • 23 comments

Hello

I recently updated LibSassHost in my project to 1.3.1 and with the following .scss file am getting an error. The bootstrap.scss file is in the same folder as the file with this code. Any help would be appreciated.

` $enable-gradients: true; $enable-shadows: true; $enable-print-styles: false;

$blue: #337ab7; $gray-100: #f5f5f5;

$border-radius: 4px;

$table-hover-bg: $blue;

$navbar-nav-link-padding-x: 15px;

$nav-link-padding-y: .833rem; $nav-link-padding-x: 1.25rem;

@import "bootstrap"; `

the error is here:

BundleTransformer.Core.Translators.AssetTranslationException Occurred.


Message: During translation of SCSS code, readed from the file '/Rep/Content/bootstrap/custom.scss', to CSS code syntax error has occurred. See more details:

Error: File to import not found or unreadable: bootstrap. on line 17:1 of Content/bootstrap/custom.scss

@import "bootstrap"; ^

Error code: 1 Description: File to import not found or unreadable: bootstrap. File: /Rep/Content/bootstrap/custom.scss Line number: 17 Column number: 1 Source fragment:

Line 17: @import "bootstrap"; ---------^ Data: TargetSite: Void InnerTranslate(BundleTransformer.Core.Assets.IAsset, LibSassHost.CompilationOptions, Boolean) HelpLink: NULL Source: BundleTransformer.SassAndScss HResult: -2146233088

Stack Trace:


at BundleTransformer.SassAndScss.Translators.SassAndScssTranslator.InnerTranslate(IAsset asset, CompilationOptions sassOptions, Boolean enableNativeMinification) at BundleTransformer.SassAndScss.Translators.SassAndScssTranslator.Translate(IList1 assets) at BundleTransformer.Core.Transformers.TransformerBase.Translate(IList1 assets, Boolean isDebugMode) at BundleTransformer.Core.Transformers.TransformerBase.Transform(IList1 assets, BundleContext bundleContext, BundleResponse bundleResponse, VirtualPathProvider virtualPathProvider, Boolean isDebugMode) at BundleTransformer.Core.Transformers.TransformerBase.Process(BundleContext bundleContext, BundleResponse bundleResponse, Boolean isDebugMode) at BundleTransformer.Core.Transformers.TransformerBase.Process(BundleContext bundleContext, BundleResponse bundleResponse) at System.Web.Optimization.Bundle.ApplyTransforms(BundleContext context, String bundleContent, IEnumerable1 bundleFiles) at System.Web.Optimization.Bundle.GenerateBundleResponse(BundleContext context) at BundleTransformer.Core.Resolvers.CustomBundleResolver.GetBundleResponse(Bundle bundle, BundleContext context) at BundleTransformer.Core.Resolvers.CustomBundleResolver.GetBundleContents(String bundleVirtualPath) at System.Web.Optimization.AssetManager.DeterminePathsToRender(IEnumerable`1 assets) at System.Web.Optimization.AssetManager.RenderExplicit(String tagFormat, String[] paths) at System.Web.Optimization.Styles.RenderFormat(String tagFormat, String[] paths) at System.Web.Optimization.Styles.Render(String[] paths) at Gwi.cSupport.Web.UI.PageBase.OnInit(EventArgs e) in C:\iSupport Source\iSupport\Main Trunk\Main Application\c.Support\Web\Framework\UI\PageBase.cs:line 72 at Gwi.cSupport.Web.UI.LicensedPageBase.OnInit(EventArgs e) in C:\iSupport Source\iSupport\Main Trunk\Main Application\c.Support\Web\Framework\UI\LicensedPageBase.cs:line 41 at System.Web.UI.Control.d__225.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Util.WithinCancellableCallbackTaskAwaitable.WithinCancellableCallbackTaskAwaiter.GetResult() at System.Web.UI.Page.d__523.MoveNext()

calebsandfort avatar Aug 14 '20 00:08 calebsandfort

Hello, Caleb!

In my case, this problem does not occur. Try making a demo project that reproduces this error and send me a link to it.

Taritsyn avatar Aug 14 '20 08:08 Taritsyn

I'm having the same issue on a WebForms WebSite project.

As a workaround you can use an absolute path:

@import "~/Rep/Content/bootstrap/bootstrap";

TristanPct avatar Oct 08 '20 11:10 TristanPct

Try upgrading to version 1.3.2.

Taritsyn avatar Oct 09 '20 17:10 Taritsyn

The issue is still there after upgrading LibSassHost (and native dependency) to 1.3.2 and BundleTransformer.SassAndScss to 1.12.22, only the absolute path starting with ~ works.

TristanPct avatar Oct 19 '20 11:10 TristanPct

Same as above. My "site.scss" is the following:

@import "overrides";
@import "offcanvas";
@import "common";
@import "bootstrap-icons/style";

I noticed that, after the application starts, if i edit the request from "site.scss" to "site.css", reload the page, and change the reference back to "site.scss" it works as expected.

I'm using last version of everything.

stefanoberetta avatar Nov 17 '20 11:11 stefanoberetta

I am also having the same issue. My code looks like this:

SassCompiler.Compile(strUserThemeSCSS, "~/CSS/input.scss");

I'm having the same issue on a WebForms WebSite project.

As a workaround you can use an absolute path:

@import "~/Rep/Content/bootstrap/bootstrap";

I even tried doing a .Replace("../", "~/") on strUserThemeSCSS for the @import paths in my SCSS as suggested by @TristanPct but this did not change anything.

I also have this import in another .scss file and it compiles fine when saved.

Error: File to import not found or unreadable: ~/Assets/Bootstrap-4.5.3/CSS/_functions.scss. on line 59:1 of ~/CSS/input.scss >> @import "~/Assets/Bootstrap-4.5.3/CSS/_functions.scss"; ^

HGCollier avatar Jan 13 '21 16:01 HGCollier

@HGCollier If you are trying to run the following code:

SassCompiler.Compile(strUserThemeSCSS, "~/CSS/input.scss");

Then first you need to write your own file manager. A good example of implementing a custom file manager, which provides access to the virtual file system, is the VirtualFileManager class from the BundleTransformer.SassAndScss package.

And then set it:

SassCompiler.FileManager = CustomFileManager();

Taritsyn avatar Jan 13 '21 16:01 Taritsyn

Keep practicing with sass bro...I am practicing maths

darwhite08 avatar Jan 13 '21 16:01 darwhite08

@HGCollier If you are trying to run the following code:

SassCompiler.Compile(strUserThemeSCSS, "~/CSS/input.scss");

Then first you need to write your own file manager. A good example of implementing a custom file manager, which provides access to the virtual file system, is the VirtualFileManager class from the BundleTransformer.SassAndScss package.

And then set it:

SassCompiler.FileManager = CustomFileManager();

I don't see this in the provided simple example, what I am trying to achieve is pretty much the same so I'm not sure why there would be any need for an external CustomFileManager? I might be misinterpreting the docs though.

HGCollier avatar Jan 13 '21 16:01 HGCollier

Try to import something else and see if the error occurs again. I met you on omegle using C++ as interest.

pulkitdtu avatar Jan 13 '21 17:01 pulkitdtu

… I'm not sure why there would be any need for an external CustomFileManager?

Original library does not support paths starting with a ~/. This feature was added to the LibSass Host after numerous requests from users.

Taritsyn avatar Jan 13 '21 17:01 Taritsyn

Try to import something else and see if the error occurs again.

I changed the @import to @import "example.scss", example.scss is in the same directory as the scss input/output file I am trying to compile.

HGCollier avatar Jan 13 '21 17:01 HGCollier

… I'm not sure why there would be any need for an external CustomFileManager?

Original library does not support paths starting with a ~/. This feature was added to the LibSass Host after numerous requests from users.

So if I were to not use ~/ I wouldn't need a CustomFileManager right? Also even when not using ~/ I still have the same error. However when I manually save the file, everything is imported fine...

This is the structure of my project:

/
    /Assets
        /Bootstrap-4.5.3
            /CSS
                _functions.scss
                ...
    /CSS
        Master.scss

My @import looks like this: @import '../Assets/Bootstrap-4.5.3/CSS/functions'.

HGCollier avatar Jan 14 '21 09:01 HGCollier

@HGCollier It depends on the type of your application. For example, a web application will most likely need an external CustomFileManager.

Taritsyn avatar Jan 14 '21 09:01 Taritsyn

@HGCollier It depends on the type of your application. For example, a web application will most likely need an external CustomFileManager.

Ok, so my project is a web application. Following this advice I have installed BundleTransformer.Core and BundleTransformer.SassAndScss via Nuget. At the top of my .cs I have put the using BundleTransformer.SassAndScss.Internal; but because the VirtualFileManager is internal I cannot access it. Is there any way around this, or am I just using the library wrong?

HGCollier avatar Jan 14 '21 10:01 HGCollier

At the top of my .cs I have put the using BundleTransformer.SassAndScss.Internal; but because the VirtualFileManager is internal I cannot access it.

VirtualFileManager class is just an example, so that you can write your own version.

Your project is based on .NET Framework or .NET Core?

Taritsyn avatar Jan 14 '21 10:01 Taritsyn

Your project is based on .NET Framework or .NET Core?

.NET Framework

HGCollier avatar Jan 14 '21 10:01 HGCollier

Then try to use the Microsoft ASP.NET Web Optimization Framework and Bundle Transformer libraries. Start reading the following sections of documentation: “Before you read” and “Examples of usage”.

I also recommend reading the “LibSass is Deprecated” article.

Taritsyn avatar Jan 14 '21 10:01 Taritsyn

Then try to use the Microsoft ASP.NET Web Optimization Framework and Bundle Transformer libraries.

Will these libraries allow me to compile SCSS from a C# script? I essentially create a new SCSS file, let's say from the press of a button and then I would like to trigger a compilation of that file without having to manually save it in my IDE.

HGCollier avatar Jan 14 '21 10:01 HGCollier

Not directly, because these libraries are responsible for asset management and bundling.

Taritsyn avatar Jan 14 '21 10:01 Taritsyn

This is why I am trying to use this library, as I need to compile my SCSS from C# on the fly.

HGCollier avatar Jan 14 '21 10:01 HGCollier

@HGCollier It is possible that an alternative solution is more suitable for you - SharpScss.

Taritsyn avatar Jan 14 '21 10:01 Taritsyn

Do you need bootstrap only? You can use any alternative and lets see if you able to accomplish the final goal. Google "Bootstrap alternatives".

pulkitdtu avatar Jan 14 '21 17:01 pulkitdtu