Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BundleTransformer for less complaining "Could not find a factory, that creates an instance of the JavaScript engine"

If you upgrade from version 1 to version 2 of BundleTransformer you may get this message:

Could not find a factory, that creates an instance of the JavaScript engine with name MsieJsEngine.

Like me, you may not even have realized you've upgraded more than just a point release.

How to fix?

like image 587
Simon_Weaver Avatar asked Oct 09 '16 02:10

Simon_Weaver


2 Answers

Version 2 DOES NOT USE WEB.CONFIG for configuration anymore

So start by removing it and read the rest of this link

https://github.com/Taritsyn/JavaScriptEngineSwitcher/wiki/How-to-upgrade-applications-to-version-2.X


Basically you will be doing the following:

  • Removing existing web.config nodes for javscript engine
  • Adding to someplace like global.asax some initialization code
  • Install Nuget packages for the engines you want to use
  • Make sure to add a using statement to be able to use extension methods (if you choose that way)

I ended up with something like this:

    using JavaScriptEngineSwitcher.Core;
    using JavaScriptEngineSwitcher.Msie;
    using JavaScriptEngineSwitcher.V8;

    ....

    public class JsEngineSwitcherConfig
    {
        public static void Configure(JsEngineSwitcher engineSwitcher)
        {
            engineSwitcher.EngineFactories
                .AddMsie(new MsieSettings
                {
                    UseEcmaScript5Polyfill = true,
                    UseJson2Library = true
                })
                .AddV8();

            engineSwitcher.DefaultEngineName = MsieJsEngine.EngineName;
        }
   }
like image 58
Simon_Weaver Avatar answered Oct 05 '22 23:10

Simon_Weaver


I'm following the instructions, but my code is now breaking on BundleConfig

var cssTransformer = new StyleTransformer();

In the name attribute of /configuration/bundleTransformer/less/jsEngine configuration element not specified a name of JavaScript engine.

If you have not installed JavaScript engine, then for correct working of this module is recommended to install one of the following NuGet packages: * JavaScriptEngineSwitcher.Msie * JavaScriptEngineSwitcher.V8 * JavaScriptEngineSwitcher.ChakraCore

After package is installed, need set a name of JavaScript engine (for example, MsieJsEngine) to the name attribute of /configuration/bundleTransformer/less/jsEngine configuration element.

like image 28
Yovav Avatar answered Oct 05 '22 23:10

Yovav