【问题标题】:JavaScript heap out of memory on Azure buildAzure 构建上的 JavaScript 堆内存不足
【发布时间】:2020-06-15 23:54:45
【问题描述】:

我正在使用带有 Angular 和 .NET Core 的 aspnetboilerplate。当我尝试在 Azure 上部署应用程序时,它显示:

致命错误:接近堆限制的无效标记压缩分配失败 - JavaScript 堆内存不足

这是我的天蓝色管道:

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'

在 package.json 文件中,我添加了 build-prod 属性。

"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"
  },

【问题讨论】:

    标签: node.js azure aspnetboilerplate ng-build


    【解决方案1】:

    解决方案:

    管道.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"
      },
    

    构建大约需要 30 分钟。但这是另一个已知问题

    【讨论】:

    • 您还可以找到其他解决方案吗?
    【解决方案2】:

    Azure DevOps 中的 Azure Pipeline 解决方案:

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

    在您的构建任务中将环境变量NODE_OPTIONS 设置为--max_old_space_size=16384

    【讨论】:

      猜你喜欢
      • 2019-01-22
      • 1970-01-01
      • 2018-02-10
      • 2019-10-13
      • 2019-09-14
      • 2021-09-19
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多