4

I' m using aspnetboilerplate with Angular and .NET Core. When i try to deploy application on Azure it shows:

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

This is my azure pipeline:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '12.x'
  displayName: 'Install Node.js'

- script: |
    npm install -g @angular/cli
    npm install
    npm run build-prod
    ng build --c=production 
  displayName: 'npm install and build'

- task: CopyFiles@2
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)/dist'
    Contents: '**'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'
    CleanTargetFolder: true
    OverWrite: true

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

and in the package.json file i' ve added the build-prod property.

"scripts": {
    "ng": "ng",
    "start": "ng serve --host 0.0.0.0 --port 4200",
    "hmr": "ng serve --host 0.0.0.0 --port 4200 --hmr",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor",
    "lint": "tslint --force --project src/tsconfig.json src/**/*.ts -t verbose",
    "build-prod": "node --max-old-space-size=8000 ./node_modules/@angular/cli/bin/ng"
  },
C1X
  • 665
  • 4
  • 14
  • 25

5 Answers5

7

Solution for Azure Pipeline in Azure DevOps:

- task: PowerShell@2
  displayName: Build
  env:
    NODE_OPTIONS: --max_old_space_size=16384

Set the Environment Variable NODE_OPTIONS with value --max_old_space_size=16384 in your Build-Task.

MrzJkl
  • 173
  • 1
  • 9
2

You can set the NODE_OPTIONS in the variables section of the yaml pipeline:

variables:
  NODE_OPTIONS: --max_old_space_size=4096
miraco
  • 298
  • 5
  • 10
  • This was an easy solution that worked great in a non-YAML (classic) Pipeline. I added it to the Pipeline's Variable table. – kenswdev Sep 01 '23 at 22:44
1

Solution:

pipeline.yml

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '12.x'
  displayName: 'Install Node.js'

- script: |
    npm install -g @angular/cli
    npm install
    npm run build-prod
  displayName: 'npm install and build'

- task: CopyFiles@2
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)/dist'
    Contents: '**'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'
    CleanTargetFolder: true
    OverWrite: true

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

package.json

"scripts": {
    "ng": "ng",
    "start": "ng serve --host 0.0.0.0 --port 4200",
    "hmr": "ng serve --host 0.0.0.0 --port 4200 --hmr",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor",
    "lint": "tslint --force --project src/tsconfig.json src/**/*.ts -t verbose",
    "build-prod": "node --max-old-space-size=8000 ./node_modules/@angular/cli/bin/ng build --configuration=production"
  },

and the build will take about 30 minutes.. but this is another known problem

C1X
  • 665
  • 4
  • 14
  • 25
1

I manually trigger a deployment from the Azure extension in VS Code (rather than using the pipeline per other answers). I had to increase the memory allocation in package.json as follows to resolve this issue:

"build": "react-scripts build --max_old_space_size=16384"

But I also had to scale up the Azure server to the next tier, with more RAM (i.e. the step above on its own did not resolve the problem, as there wasn't sufficient RAM on the server to be allocated).

Jess
  • 151
  • 12
0
  - task: PowerShell@2
    displayName: Increase memory
    inputs:
      targetType: 'inline'
      script: |
          $env:NODE_OPTIONS="--max-old-space-size=8192"
Alex
  • 1