Aspnetcore-angular-universal: Azure Devops builds failing - Javascript Heap out of memory

Created on 31 Jul 2019  路  6Comments  路  Source: TrilonIO/aspnetcore-angular-universal

Getting "Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory" on all azure builds. Local builds are fine.

PS: I have seen Issue# 262

What did I try?

  1. I tried all steps listed on Issue 262
  2. Tried all solutions listed at https://developercommunity.visualstudio.com/content/problem/398343/azure-devops-pipeline-fatal-error-ineffective-mark.html
  3. Edited csproject msbuild task RunWebpack to add node --max_old_space_size=4096. I see this gets executed twice and max_old_space_size is being ignored the second time. See below error.
<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
    <Exec Command="npm install" />
    <Exec Command="node --max_old_space_size=4096 node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
    <Exec Command="node --max_old_space_size=4096 node_modules/webpack/bin/webpack.js --env.prod" />
    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="wwwroot\dist\**; ClientApp\dist\**" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>

Exact Error:

Getting error at "RunWebpackBuild"
EXEC(0,0): Error : Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Web.csproj(119,5): Error MSB3073: The command "node node_modules/webpack/bin/webpack.js --env.prod" exited with code 134.
Process 'msbuild.exe' exited with code '1'.

Location of Error:

node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod
  env = {"prod":true}
  Hash: 2e377ce94a017387bb5e67cbd26fb64a7dcb8f06
  Version: webpack 4.20.2
  Child
      Hash: 2e377ce94a017387bb5e
      Time: 2455ms
      Built at: 07/31/2019 6:47:48 PM
          Asset     Size  Chunks                    Chunk Names
      vendor.js  273 KiB       0  [emitted]  [big]  vendor
      Entrypoint vendor [big] = vendor.js

  Child
      Hash: 67cbd26fb64a7dcb8f06
      Time: 17716ms
      Built at: 07/31/2019 6:48:03 PM
          Asset     Size  Chunks             Chunk Names
      vendor.js  1.9 MiB       0  [emitted]  vendor
      Entrypoint vendor = vendor.js

node node_modules/webpack/bin/webpack.js --env.prod
[error]EXEC(0,0): Error : Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
[debug]Processed: vso[task.logissue type=Error;sourcepath=EXEC;linenumber=0;columnnumber=0;code=;]Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
EXEC : FATAL error : Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory [D:\a\3\s\SCACostingProgram\MAIN\SCACP\SCACP.Web\SCACP.Web.csproj]
   1: 00007FF79553C6AA v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4506
   2: 00007FF795517416 node::MakeCallback+4534
   3: 00007FF795517D90 node_module_register+2032
   4: 00007FF79583189E v8::internal::FatalProcessOutOfMemory+846
   5: 00007FF7958317CF v8::internal::FatalProcessOutOfMemory+639
   6: 00007FF795A17F94 v8::internal::Heap::MaxHeapGrowingFactor+9620
   7: 00007FF795A0EF76 v8::internal::ScavengeJob::operator=+24550
   8: 00007FF795A0D5CC v8::internal::ScavengeJob::operator=+17980
   9: 00007FF795A16317 v8::internal::Heap::MaxHeapGrowingFactor+2327
  10: 00007FF795A16396 v8::internal::Heap::MaxHeapGrowingFactor+2454
  11: 00007FF795B40637 v8::internal::Factory::NewFillerObject+55
  12: 00007FF795BBD826 v8::internal::operator<<+73494
  13: 000002B2769DC5C1 

Most helpful comment

I do not know why but I got this error last week. I fixed our automated build by updating the webpack script as follows (I put a random higher number).

"build:webpack": "webpack --max_old_space_size=16384 --progress --color",

However, later I read that apparently, the correct approach is to set an environment variable

NODE_OPTIONS=--max_old_space_size=16384

Hope it helps.

All 6 comments

I do not know why but I got this error last week. I fixed our automated build by updating the webpack script as follows (I put a random higher number).

"build:webpack": "webpack --max_old_space_size=16384 --progress --color",

However, later I read that apparently, the correct approach is to set an environment variable

NODE_OPTIONS=--max_old_space_size=16384

Hope it helps.

@alexbenitez I have tried
"build:webpack": "webpack --max_old_space_size=16384 --progress --color",
and it didnt work.

How to set the environment variable for Azure DevOps build agents? Where does the line of code you show go, file, location etc?

@alexbenitez I just added a Azure powershell task to pipeline, just before build to set environment variable at machine level. It didn't work either.

See YAML below

steps:
- task: AzurePowerShell@3
  displayName: 'Azure PowerShell script: InlineScript'
  inputs:
    azureSubscription: 'NYCSCA Azure Dev/Test (ea91a274-55c6-461c-a11d-758ef02c2698)'
    ScriptType: InlineScript
    Inline: '[Environment]::SetEnvironmentVariable("NODE_OPTIONS", "--max_old_space_size=4096", "Machine")'
    FailOnStandardError: true
    azurePowerShellVersion: LatestVersion

Update:
Anyone trying this on Azure build pipeline. I finally got it succeeded. Increased memory to 16384. Please note this step alone wasn't working. Needed same changes in csproj and package.json

Steps

  1. Add an Azure build pipeline task -> Azure powershell script:Inlinescript before Compile with below settings
    steps:
- task: AzurePowerShell@3
  displayName: 'Azure PowerShell script: InlineScript'
  inputs:
    azureSubscription: 'NYCSCA Azure Dev/Test (ea91a274-55c6-461c-a11d-758ef02c2698)'
    ScriptType: InlineScript
    Inline: '[Environment]::SetEnvironmentVariable("NODE_OPTIONS", "--max_old_space_size=16384", "Machine")'
    FailOnStandardError: true
    azurePowerShellVersion: LatestVersion

@alexbenitez thanks for the tip NODE_OPTIONS=--max_old_space_size=16384. It worked perfectly.

Update:
Anyone trying this on Azure build pipeline. I finally got it succeeded. Increased memory to 16384. Please note this step alone wasn't working. Needed same changes in csproj and package.json

Steps

  1. Add an Azure build pipeline task -> Azure powershell script:Inlinescript before Compile with below settings
    steps:
- task: AzurePowerShell@3
  displayName: 'Azure PowerShell script: InlineScript'
  inputs:
    azureSubscription: 'NYCSCA Azure Dev/Test (ea91a274-55c6-461c-a11d-758ef02c2698)'
    ScriptType: InlineScript
    Inline: '[Environment]::SetEnvironmentVariable("NODE_OPTIONS", "--max_old_space_size=16384", "Machine")'
    FailOnStandardError: true
    azurePowerShellVersion: LatestVersion

@codehippie1 what changes are required for csproj and package.json files?

Was this page helpful?
0 / 5 - 0 ratings