Reputation: 795
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"
},
Upvotes: 13
Views: 23860
Reputation: 3378
For @miraco answer, I have to change to this format,
variables:
- name: NODE_OPTIONS
value: --max_old_space_size=4096
Upvotes: 0
Reputation: 211
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).
Upvotes: 2
Reputation: 418
You can set the NODE_OPTIONS in the variables section of the yaml pipeline:
variables:
NODE_OPTIONS: --max_old_space_size=4096
Upvotes: 7
Reputation: 1
- task: PowerShell@2
displayName: Increase memory
inputs:
targetType: 'inline'
script: |
$env:NODE_OPTIONS="--max-old-space-size=8192"
Upvotes: 0
Reputation: 341
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.
Upvotes: 13
Reputation: 795
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
Upvotes: 1