首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASP.NET Core2.1Web应用程序在作为Docker应用程序运行时出现React.Aspnet错误

ASP.NET Core2.1Web应用程序在作为Docker应用程序运行时出现React.Aspnet错误
EN

Stack Overflow用户
提问于 2019-04-15 00:33:18
回答 1查看 488关注 0票数 0

我有一个ASP.NET Core2.1Web应用程序和React.aspnet。在IIS中运行时,它运行得非常完美。但是,当我在Docker中运行它时,应用程序仍然可以成功运行,但是具有React的视图页失败了,出现了以下错误:

代码语言:javascript
复制
  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如下所示:

代码语言:javascript
复制
    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"]

有人能给出一些关于问题所在的建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-16 21:38:24

通过安装不同操作系统的JavaScriptEngineSwitcher.ChakraCore.版本,我设法解决了这个问题。

代码语言:javascript
复制
<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" />

根据wiki页面 for ChakraCore:

此包不包含ChakraCore的本机实现。因此,您需要为您的平台选择和安装最合适的软件包。

通过安装所有版本,任何拉下这个包的人都可以在不同的操作系统上运行和构建坞映像,而不必再担心包的依赖性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55681276

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档