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

2

7

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?

Pratfall answered 9/10, 2016 at 2:44 Comment(0)
P
14

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;
        }
   }
Pratfall answered 9/10, 2016 at 2:47 Comment(0)
F
1

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.

Forbes answered 13/11, 2016 at 4:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.