首页 > 解决方案 > 部署到 Azure Web App 时出现 ChakraCore.dll 异常

问题描述

我有一个应用程序,它使用Babel将一些动态 JS 转换为 es5 兼容的 JS 以便在 IE 浏览器中使用。

此设置在本地完美运行,但是一旦部署到 Azure,我在尝试调用时不断收到以下异常

var babel = ReactEnvironment.Current.Babel;

异常触发:

React.TinyIoC.TinyIoCResolutionException: Unable to resolve type: React.ReactEnvironment (Error getting vue module script) ---> React.TinyIoC.TinyIoCResolutionException: Unable to resolve type: React.JavaScriptEngineFactory ---> JavaScriptEngineSwitcher.Core.JsEngineLoadException: Failed to create instance of the ChakraCoreJsEngine. Most likely it happened, because the 'ChakraCore.dll' assembly or one of its dependencies was not found. Try to install the JavaScriptEngineSwitcher.ChakraCore.Native.win-x86 package via NuGet. In addition, you still need to install the Microsoft Visual C++ Redistributable for Visual Studio 2017 (https://www.visualstudio.com/downloads/#microsoft-visual-c-redistributable-for-visual-studio-2017). ---> System.DllNotFoundException: Unable to load DLL 'ChakraCore' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at React.TinyIoC.TinyIoCContainer.ConstructType(System.Type, System.Type, System.Reflection.ConstructorInfo, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
at React.TinyIoC.TinyIoCContainer+CustomObjectLifetimeFactory.GetObject(System.Type, React.TinyIoC.TinyIoCContainer, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
at React.TinyIoC.TinyIoCContainer.ResolveInternal(React.TinyIoC.TinyIoCContainer+TypeRegistration, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
at React.TinyIoC.TinyIoCContainer.Resolve(System.Type)
at React.TinyIoC.TinyIoCContainer.Resolve()
at App.Controllers.ComponentController+<ModuleRegistrationIE11>d__4.MoveNext()
--- End of inner exception stack trace ---
at React.TinyIoC.TinyIoCContainer.ConstructType(System.Type, System.Type, System.Reflection.ConstructorInfo, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
at React.TinyIoC.TinyIoCContainer+SingletonFactory.GetObject(System.Type, React.TinyIoC.TinyIoCContainer, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
at React.TinyIoC.TinyIoCContainer.ResolveInternal(React.TinyIoC.TinyIoCContainer+TypeRegistration, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
at React.TinyIoC.TinyIoCContainer.ConstructType(System.Type, System.Type, System.Reflection.ConstructorInfo, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
--- End of inner exception stack trace ---
at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine..ctor(JavaScriptEngineSwitcher.ChakraCore.ChakraCoreSettings)
at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngineFactory.CreateEngine()
at JSPool.JsPool`2.CreateEngine()
at JSPool.JsPool`2.PopulateEngines()
at JSPool.JsPool`2..ctor()
at React.JavaScriptEngineFactory.CreatePool()
at React.JavaScriptEngineFactory..ctor(JavaScriptEngineSwitcher.Core.IJsEngineSwitcher, React.IReactSiteConfiguration, React.ICache, React.IFileSystem)
at lambda_method(System.Runtime.CompilerServices.Closure, System.Object[])
at React.TinyIoC.TinyIoCContainer.ConstructType(System.Type, System.Type, System.Reflection.ConstructorInfo, React.TinyIoC.NamedParameterOverloads, React.TinyIoC.ResolveOptions)
--- End of inner exception stack trace ---
at JavaScriptEngineSwitcher.ChakraCore.JsRt.NativeMethods.JsCreateRuntime(JavaScriptEngineSwitcher.ChakraCore.JsRt.JsRuntimeAttributes, JavaScriptEngineSwitcher.ChakraCore.JsRt.JsThreadServiceCallback, JavaScriptEngineSwitcher.ChakraCore.JsRt.JsRuntime&)
at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine+<>c__DisplayClass10_1.<.ctor>b__0()
at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher+<>c__DisplayClass11_0.<Invoke>b__0()
at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.StartThread()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.InnnerInvoke(System.Func`1[[System.Object, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]])
at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.Invoke(System.Action)
at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine..ctor(JavaScriptEngineSwitcher.ChakraCore.ChakraCoreSettings)

该异常表明很可能缺少 ChakraCore.dll 或 Visual Studio 2017 的 C++ Redistributable。我假设 Azure 中存在可再发行组件,因为https://feedback.azure.com/forums/355860-azure-functions/suggestions/31130971-install-visual-c-2015-or-2017-redistributale

检查 Azure 中的文件时,ChakraCore.dll 似乎存在 在此处输入图像描述

我也试过这里的建议卸载和重新安装所有相关包https://github.com/reactjs/React.NET/issues/400

标签: c#azurebabeljschakracore

解决方案


好的,多亏了一些绝望的试验和错误,这只是添加对其他平台关于 JavaScriptEngineSwitcher.ChakraCore.Native 包的支持的一个案例,我最初只有 win-x64,但安装了 win-x86 并对其进行了排序并得到了它在 Azure 中工作。

这是我为使我的应用程序在 Azure 中成功运行而安装的软件包的最终结果:

<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore" Version="3.1.1" />
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x64" Version="3.1.1" />
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x86" Version="3.1.1" />
<PackageReference Include="JavaScriptEngineSwitcher.Core" Version="3.1.0" />
<PackageReference Include="JavaScriptEngineSwitcher.Extensions.MsDependencyInjection" Version="3.1.0" />
<PackageReference Include="JSPool" Version="4.0.0" />

推荐阅读