我有一个带有React.aspnet的ASP.NET Core 2.1 Web应用程序。在IIS中运行时,它可以完美运行。但是当我在Docker中运行它时,应用程序仍然可以成功运行,但是带有React的视图页面失败,并显示以下错误:
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
An unhandled exception has occurred while executing the request.
React.TinyIoC.TinyIoCResolutionException: Unable to resolve type: React.ReactEnvironment ---> 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 'libChakraCore.so' assembly or one of its dependencies was not found. Try to install the JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64 package via NuGet. ---> System.DllNotFoundException: Unable to load shared library 'ChakraCore' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libChakraCore: cannot open shared object file: No such file or directory
at JavaScriptEngineSwitcher.ChakraCore.JsRt.NativeMethods.JsCreateRuntime(JsRuntimeAttributes attributes, JsThreadServiceCallback threadService, JsRuntime& runtime)
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()
--- End of stack trace from previous location where exception was thrown ---
at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.InnnerInvoke(Func`1 del)
at JavaScriptEngineSwitcher.ChakraCore.ScriptDispatcher.Invoke(Action action)
at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine..ctor(ChakraCoreSettings settings)
--- End of inner exception stack trace ---
at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngine..ctor(ChakraCoreSettings settings)
at JavaScriptEngineSwitcher.ChakraCore.ChakraCoreJsEngineFactory.CreateEngine()
at JSPool.JsPool`2.CreateEngine()
at JSPool.JsPool`2.PopulateEngines()
at JSPool.JsPool`2..ctor(JsPoolConfig`1 config)
at React.JavaScriptEngineFactory.CreatePool()
at React.JavaScriptEngineFactory..ctor(IJsEngineSwitcher jsEngineSwitcher, IReactSiteConfiguration config, ICache cache, IFileSystem fileSystem)
at lambda_method(Closure , Object[] )
at React.TinyIoC.TinyIoCContainer.ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options)
--- End of inner exception stack trace ---
at React.TinyIoC.TinyIoCContainer.ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options)
at React.TinyIoC.TinyIoCContainer.SingletonFactory.GetObject(Type requestedType, TinyIoCContainer container, NamedParameterOverloads parameters, ResolveOptions options)
at React.TinyIoC.TinyIoCContainer.ResolveInternal(TypeRegistration registration, NamedParameterOverloads parameters, ResolveOptions options)
at React.TinyIoC.TinyIoCContainer.ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options)
--- End of inner exception stack trace ---
at React.TinyIoC.TinyIoCContainer.ConstructType(Type requestedType, Type implementationType, ConstructorInfo constructor, NamedParameterOverloads parameters, ResolveOptions options)
at React.TinyIoC.TinyIoCContainer.CustomObjectLifetimeFactory.GetObject(Type requestedType, TinyIoCContainer container, NamedParameterOverloads parameters, ResolveOptions options)
at React.TinyIoC.TinyIoCContainer.ResolveInternal(TypeRegistration registration, NamedParameterOverloads parameters, ResolveOptions options)
at React.TinyIoC.TinyIoCContainer.Resolve[ResolveType]()
at React.AspNet.BabelFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)
尝试了许多解决方案,但是没有用。我的nuget包如下所示:
我的Dockerfile如下所示:
FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS build
WORKDIR /app
EXPOSE 80
# copy csproj and restore as distinct layers
COPY *.sln .
COPY *.csproj ./
RUN dotnet restore
# copy everything else and build app
COPY . ./
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -yq nodejs build-essential
RUN npm install -g npm
RUN npm install
RUN dotnet publish -c Release -o ./out
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1 AS runtime
WORKDIR /app
COPY --from=build /app/out ./
ENTRYPOINT ["dotnet", "app.dll"]
任何人都可以提供有关可能是什么问题的提示吗?
答案 0 :(得分:0)
我设法通过安装不同操作系统特定版本的 JavaScriptEngineSwitcher.ChakraCore 来解决此问题。
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64" Version="3.0.9" />
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x64" Version="3.0.9" />
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.win-x86" Version="3.0.9" />
<PackageReference Include="JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64" Version="3.0.9" />
根据ChakraCore的wiki page:
此软件包不包含的本机实现 ChakraCore。因此,您需要选择并安装最多的 适用于您平台的软件包。
通过安装所有版本,任何拉过此软件包的人都可以在不同的OS上运行并构建docker映像,而无需再次担心软件包的依赖性。