Azure webservice 自动添加 NODE_OPTIONS 环境变量导致 jsreport 抛出 JsReportBinaryException

Azure webservice automatically adding NODE_OPTIONS environment variable causing jsreport to throw JsReportBinaryException

我目前有一个使用 ASP.NET Core 的工作 docker 图像,在我的本地图像上带有 jsreport,它在 Azure 应用服务上不起作用 运行 Linux容器。尝试任何渲染时都会抛出以下错误:

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 App Service 之间的差异到以下环境变量,这在我的本地机器上导致了同样的错误:(补充一下,这个环境变量似乎是由 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。我到目前为止还没有找到任何解决方案来解决如何禁用 Application Insights for Nodejs 以及为什么这会导致错误

你能检查一下你的配置代码吗link.

如果您遗漏了任何内容,那么您可以添加上面的内容 link 然后重试。 此外,如果您想禁用 nodejs 的应用程序洞察,请按照以下步骤操作:

  1. 在 Azure 门户中搜索 select App Services,然后 select 你的应用程序。
  2. 在应用程序的左侧菜单中,select 配置 > 应用程序设置
  3. 根据显示的值,select 属性 名称为 ApplicationInsights****Nodejs 并单击该隐藏值并将其编辑为'0'.

否则您可以在配置中添加一个应用程序设置-->应用程序设置--> + 新的应用程序设置 如下所述输入名称和值并保存。

   appInsights.defaultClient.config.disableAppInsights = true