c# - Azure webservice 自动添加 NODE_OPTIONS 环境变量导致 jsreport 抛出 JsReportBinaryException
问题描述
我目前确实有一个使用 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 App Service 与以下环境变量之间的差异,这在我的本地机器上导致了同样的错误:(添加,这个环境变量似乎是由 Azure 自动添加的)
-e NODE_OPTIONS="--require /agents/node/build/src/Loader.js"
我没有找到任何有用的信息,也没有找到在 Azure 门户配置中删除或覆盖它的方法。一种可能的解决方法是在第一次启动容器时删除此环境变量,但这似乎不是一个好的长期解决方案。有没有办法强制 Azure 不包含这个环境变量,在本地忽略它,或者我在这里遗漏了什么?
更新:使用Environment.SetEnvironmentVariable("NODE_OPTIONS", "");
at start 确实“解决”了这个错误,但仍然没有找到任何令人满意的解决方案。
Update2:我发现它是由 Application Insights nodejs 支持引起的。他们添加了NODE_OPTIONS
环境变量(另请参见https://newreleases.io/project/github/microsoft/ApplicationInsights-node.js/release/1.7.0)以尽快且可靠地加载 Application Insights。到目前为止,我还没有找到任何解决方案来解决如何禁用 Application Insights for Nodejs,也没有找到导致错误的原因
解决方案
您可以检查此链接中提到的配置代码吗?
如果您错过了任何内容,那么您可以从上面的链接中添加内容并重试。此外,如果您想禁用 nodejs 的应用程序洞察力,请按照以下步骤操作:
- 在 Azure 门户中搜索并选择App Services,然后选择您的应用。
- 在应用程序的左侧菜单中,选择配置>应用程序设置。
- 从显示的值中,选择名称为ApplicationInsights****Nodejs的属性,然后单击该隐藏值并将其编辑为“0”。
否则,您可以在配置中添加应用程序设置 - >应用程序设置 - > +新应用程序设置给出名称和值,如下所述并保存。
appInsights.defaultClient.config.disableAppInsights = true
推荐阅读
- templates - 是否可以显示 collection.template 中的所有产品?
- reactjs - 浏览器后退按钮单击无法加载目标页面css,它仍然显示源页面css
- node.js - 使用 API 上传的视频被锁定为私有
- sql-server - SQL Server Express 上的 SQL 电子邮件配置
- android - Flutter:如何使用 shared_preference 存储“收藏列表”
- excel - Excel:合并来自 2 个表的数据
- vue.js - vuex store action的mock不mock
- c# - 例外:尝试使用 Microsoft 登录时关联失败
- sql - 没有 ROW_NUMBER() 的 SQL 编号行与 Partition By ?玛丽亚数据库 10.1
- amazon-web-services - 最近上传的 AWS S3 文件未更新