I do currently have a working docker image using ASP.NET Core with jsreport on my local image, that does not work on a Azure App Service running Linux containers. The following error is thrown when any rendering is tried:
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)
I have tracked down the difference between my machine an the Azure App Service to the following environment variable, that causes the same error on my local machine: (to a add, this environment variable seems to be added automatically by Azure)
-e NODE_OPTIONS="--require /agents/node/build/src/Loader.js"
I did not found any usefull information about this and did not find a way to remove nor to override it in the Azure Portal configuration either. A possible workaround would be to remove this environment variable the first time the container is started, but this does not seem like a good longtime solution. Is there a way to force Azure to not include this environment variable, to ignore it locally or am I missing something else here?
Update:
Using Environment.SetEnvironmentVariable("NODE_OPTIONS", "");
at start does indeed "solve" this error, but still did not found any satisfing solution.
Update2:
I have found out, that it is caused by the Application Insights nodejs support. They have added the NODE_OPTIONS
environment variable (see also https://newreleases.io/project/github/microsoft/ApplicationInsights-node.js/release/1.7.0) to load Application Insights as soon and reliable as possible. I do as of now have not found any solution to how to disable Application Insights for Nodejs nor why this is causing an Error
The original Answer was deleted.
The solution was to set appInsights.defaultClient.config.disableAppInsights
to true
in the App Service Configuration
.