我目前在本地镜像上有一个使用 ASP.NET Core 和 jsreport 的可用 docker 镜像,该镜像不适用于运行 Linux 容器的 Azure 应用服务。尝试任何渲染时都会引发以下错误:
An unhandled exception has occurred while executing the request.
jsreport.Local.JsReportBinaryException: Error rendering report: internal/modules/cjs/loader.js:58const internalModuleStat = function (f) { return require('fs').internalModuleStat(f); }; ^TypeError: require(...).internalModuleStat is not a function at internalModuleStat (internal/modules/cjs/loader.js:58:64) at stat (internal/modules/cjs/loader.js:137:18) at Function.Module._findPath (internal/modules/cjs/loader.js:667:16) at Function.Module._resolveFilename (internal/modules/cjs/loader.js:967:27) at Function.Module._load (internal/modules/cjs/loader.js:862:27) at Module.require (internal/modules/cjs/loader.js:1042:19) at Module._preloadModules (internal/modules/cjs/loader.js:1296:12) at loadPreloadModules (internal/bootstrap/pre_execution.js:449:5) at prepareMainThreadExecution (internal/bootstrap/pre_execution.js:73:3) at internal/bootstrap/pkg.js:7:1
at jsreport.Local.Internal.LocalUtilityReportingService.RenderAsync(String requestString, CancellationToken ct)
at jsreport.AspNetCore.JsReportMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
我已经追踪到我的计算机与 Azure 应用服务之间的差异到以下环境变量,这导致我的本地计算机上出现相同的错误:(补充一下,此环境变量似乎是由 Azure 自动添加的)
-e NODE_OPTIONS="--require /agents/node/build/src/Loader.js"
我没有找到任何关于此的有用信息,也没有找到在 Azure 门户配置中删除或覆盖它的方法。一种可能的解决方法是在容器第一次启动时删除此环境变量,但这似乎不是一个好的长期解决方案。有没有办法强制 Azure 不包含此环境变量,在本地忽略它,还是我在这里遗漏了其他内容?
更新:
在开始时使用 Environment.SetEnvironmentVariable("NODE_OPTIONS", "");
确实“解决”了这个错误,但仍然没有找到任何令人满意的解决方案。
更新2:
我发现这是由 Application Insights Nodejs 支持引起的。他们添加了 NODE_OPTIONS
环境变量(另请参阅 https://newreleases.io/project/github/microsoft/ApplicationInsights-node.js/release/1.7.0 )以尽快且可靠地加载 Application Insights。到目前为止,我还没有找到任何解决方案来解决如何禁用 Nodejs 的 Application Insights 的问题,也没有找到为什么这会导致错误
最佳答案
原始答案已被删除。
解决方案是在应用服务配置
中将appInsights.defaultClient.config.disableAppInsights
设置为true
。
关于c# - Azure Web服务自动添加NODE_OPTIONS环境变量导致jsreport抛出JsReportBinaryException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68530811/